From: Hannu Niemistö Date: Tue, 16 Aug 2016 09:24:37 +0000 (+0300) Subject: merged svn revision 33114 and added desktop and help plugins X-Git-Tag: v1.25.0~176^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=6a4a43b278d6819c660182eb4954524d1757e077;p=simantics%2Fplatform.git merged svn revision 33114 and added desktop and help plugins --- diff --git a/bundles/org.simantics.datatypes/scl/Simantics/GUID.scl b/bundles/org.simantics.datatypes/scl/Simantics/GUID.scl index 99fd4f4a0..b6e3ede79 100644 --- a/bundles/org.simantics.datatypes/scl/Simantics/GUID.scl +++ b/bundles/org.simantics.datatypes/scl/Simantics/GUID.scl @@ -4,7 +4,11 @@ import "Simantics/Ontologies" importJava "org.simantics.datatypes.literal.GUID" where data GUID - + +instance Show GUID where + show guid = guidIndexString guid + +importJava "org.simantics.datatypes.literal.GUID" where @JavaName "BINDING" guidBinding :: Binding a @JavaName random diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/GraphDebugger.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/GraphDebugger.java index ca2fa2190..4d2a19dfe 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/GraphDebugger.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/GraphDebugger.java @@ -963,8 +963,10 @@ public class GraphDebugger extends Composite { Layer0 L0 = Layer0.getInstance(graph); if (graph.isInstanceOf(r, L0.Assertion)) { Resource pred = graph.getSingleObject(r, L0.HasPredicate); - Resource obj = graph.getSingleObject(r, L0.HasObject); - String tmp = htmlEscape( getResourceName(graph, pred) + " -> " + getResourceName(graph, obj) + " (Assertion)" ); + // Don't know how I encountered this but it seems to be possible in some cases.. + // Resource obj = graph.getSingleObject(r, L0.HasObject); + Resource obj = graph.getPossibleObject(r, L0.HasObject); + String tmp = htmlEscape( getResourceName(graph, pred) + " -> " + (obj == null ? "No object ?" : getResourceName(graph, obj)) + " (Assertion)" ); name = tmp.substring(0, Math.min(80, tmp.length())); } else { String resourceName = getResourceName(graph, r); diff --git a/bundles/org.simantics.desktop.product/.classpath b/bundles/org.simantics.desktop.product/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.desktop.product/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.desktop.product/.project b/bundles/org.simantics.desktop.product/.project new file mode 100644 index 000000000..9cf57229a --- /dev/null +++ b/bundles/org.simantics.desktop.product/.project @@ -0,0 +1,28 @@ + + + org.simantics.desktop.product + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.desktop.product/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.desktop.product/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.desktop.product/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.desktop.product/META-INF/MANIFEST.MF b/bundles/org.simantics.desktop.product/META-INF/MANIFEST.MF new file mode 100644 index 000000000..030200c24 --- /dev/null +++ b/bundles/org.simantics.desktop.product/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Desktop Product +Bundle-SymbolicName: org.simantics.desktop.product;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Semantum Oy +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/bundles/org.simantics.desktop.product/build.properties b/bundles/org.simantics.desktop.product/build.properties new file mode 100644 index 000000000..6f20375d6 --- /dev/null +++ b/bundles/org.simantics.desktop.product/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/org.simantics.desktop.product/plugin.xml b/bundles/org.simantics.desktop.product/plugin.xml new file mode 100644 index 000000000..683c16dc5 --- /dev/null +++ b/bundles/org.simantics.desktop.product/plugin.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/org.simantics.desktop.product/simantics-desktop.product b/bundles/org.simantics.desktop.product/simantics-desktop.product new file mode 100644 index 000000000..af09f04b7 --- /dev/null +++ b/bundles/org.simantics.desktop.product/simantics-desktop.product @@ -0,0 +1,70 @@ + + + + + + + + + The desktop environment for Simantics products. + + + + + + + + --launcher.XXMaxPermSize +192m +-fixerrors +-data +@noDefault +-cssTheme +org.eclipse.e4.ui.css.theme.e4_classic + + -ea +-Xmx500M +-Xshare:off +-XX:MaxPermSize=192m +-Djava.net.preferIPv4Stack=true +-Dorg.simantics.workbench.application.showFastViewBars=false +-Dorg.simantics.workbench.application.showPerspectiveBar=false +-Dorg.simantics.workbench.application.excludePerspectiveFromTitle=true +-Declipse.workaround.bug467000=true + + -Dorg.osgi.framework.os.name=win32 + + + + + + + + + + + + + + org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 + + + + http://www.eclipse.org/legal/epl-v10.html + + + + + + + + + + + + + + + + + diff --git a/bundles/org.simantics.desktop.ui.ontology/.classpath b/bundles/org.simantics.desktop.ui.ontology/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.desktop.ui.ontology/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.desktop.ui.ontology/.project b/bundles/org.simantics.desktop.ui.ontology/.project new file mode 100644 index 000000000..6e56266d9 --- /dev/null +++ b/bundles/org.simantics.desktop.ui.ontology/.project @@ -0,0 +1,34 @@ + + + org.simantics.desktop.ui.ontology + + + + + + org.simantics.graph.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.simantics.graph.nature + + diff --git a/bundles/org.simantics.desktop.ui.ontology/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.desktop.ui.ontology/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.desktop.ui.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.desktop.ui.ontology/META-INF/MANIFEST.MF b/bundles/org.simantics.desktop.ui.ontology/META-INF/MANIFEST.MF new file mode 100644 index 000000000..8790e6969 --- /dev/null +++ b/bundles/org.simantics.desktop.ui.ontology/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: http://www.simantics.org/DesktopUI +Bundle-SymbolicName: org.simantics.desktop.ui.ontology +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Semantum Oy +Require-Bundle: org.simantics.layer0, + org.simantics.project.ontology;bundle-version="1.2.0", + org.simantics.silk.ontology;bundle-version="1.1.0", + org.simantics.viewpoint.ontology;bundle-version="1.2.0", + org.simantics.modeling.ontology;bundle-version="1.2.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/bundles/org.simantics.desktop.ui.ontology/build.properties b/bundles/org.simantics.desktop.ui.ontology/build.properties new file mode 100644 index 000000000..022de1735 --- /dev/null +++ b/bundles/org.simantics.desktop.ui.ontology/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + graph.tg diff --git a/bundles/org.simantics.desktop.ui.ontology/graph.tg b/bundles/org.simantics.desktop.ui.ontology/graph.tg new file mode 100644 index 000000000..02d354a20 Binary files /dev/null and b/bundles/org.simantics.desktop.ui.ontology/graph.tg differ diff --git a/bundles/org.simantics.desktop.ui.ontology/graph/DesktopUI.pgraph b/bundles/org.simantics.desktop.ui.ontology/graph/DesktopUI.pgraph new file mode 100644 index 000000000..c583c4d9e --- /dev/null +++ b/bundles/org.simantics.desktop.ui.ontology/graph/DesktopUI.pgraph @@ -0,0 +1,31 @@ +L0 = +PROJECT = +SILK = +VP = +MOD = + +DesktopUI = : L0.Ontology + @L0.new + +DesktopUI.SCLMain : L0.SCLModule + L0.SCLModule.definition _ : L0.String + @L0.loadString "scl/SCLMain.scl" + +DesktopUI.BrowseContext : VP.BrowseContext + VP.BrowseContext.Includes PROJECT.ProjectBrowseContext + VP.BrowseContext.HasChildContribution MOD.Contributions.ModelLibraries + +DesktopUI.FileMenuNewActionContext : VP.BrowseContext + VP.BrowseContext.IsIncludedIn PROJECT.ProjectFileMenuNewActionContext + VP.BrowseContext.HasActionContribution _ : VP.ActionContribution + L0.HasLabel "Shared Library" + VP.ActionContribution.HasImage SILK.folder + VP.ActionContribution.HasCategory VP.EditActionCategory + VP.ActionContribution.HasNodeType PROJECT.Project + VP.ActionContribution.HasAction ACTIONS.NewSharedLibrary + +ACTIONS = DesktopUI.Actions : L0.Library + +ACTIONS.NewSharedLibrary + @MOD.sclAction "newSharedLibraryAction" + \ No newline at end of file diff --git a/bundles/org.simantics.desktop.ui.ontology/graph/scl/SCLMain.scl b/bundles/org.simantics.desktop.ui.ontology/graph/scl/SCLMain.scl new file mode 100644 index 000000000..f48a765e0 --- /dev/null +++ b/bundles/org.simantics.desktop.ui.ontology/graph/scl/SCLMain.scl @@ -0,0 +1,6 @@ +include "Simantics/All" + +newSharedLibraryAction :: Resource -> () +newSharedLibraryAction res = do + syncWrite (\() -> createSharedOntologyWithUI L0.SharedOntology) + () diff --git a/bundles/org.simantics.desktop.ui/.classpath b/bundles/org.simantics.desktop.ui/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.desktop.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.desktop.ui/.project b/bundles/org.simantics.desktop.ui/.project new file mode 100644 index 000000000..69ab42f6e --- /dev/null +++ b/bundles/org.simantics.desktop.ui/.project @@ -0,0 +1,28 @@ + + + org.simantics.desktop.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.desktop.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.desktop.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.desktop.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.desktop.ui/META-INF/MANIFEST.MF new file mode 100644 index 000000000..28c6e2018 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Desktop UI +Bundle-SymbolicName: org.simantics.desktop.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.desktop.ui.internal.Activator +Bundle-Vendor: Semantum Oy +Require-Bundle: org.simantics.workbench;bundle-version="1.5.1", + org.eclipse.epp.mpc.core;bundle-version="1.1.1", + org.eclipse.epp.mpc.help.ui;bundle-version="1.1.1", + org.eclipse.epp.mpc.ui;bundle-version="1.1.1", + org.eclipse.ui.browser;bundle-version="3.3.100", + org.simantics.platform.ui.ontology;bundle-version="1.0.0", + org.simantics.spreadsheet.ontology;bundle-version="1.2.0", + org.simantics.spreadsheet.common;bundle-version="1.1.0", + org.simantics.selectionview;bundle-version="1.0.0", + org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150407-1430", + org.simantics.spreadsheet.graph, + org.simantics.spreadsheet;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy diff --git a/bundles/org.simantics.desktop.ui/build.properties b/bundles/org.simantics.desktop.ui/build.properties new file mode 100644 index 000000000..5de126191 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/build.properties @@ -0,0 +1,9 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + icons/appicon.png,\ + icons/simantics256.png,\ + icons/simantics32.png,\ + fragment.e4xmi +source.. = src/ diff --git a/bundles/org.simantics.desktop.ui/fragment.e4xmi b/bundles/org.simantics.desktop.ui/fragment.e4xmi new file mode 100644 index 000000000..64c431579 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/fragment.e4xmi @@ -0,0 +1,13 @@ + + + + + + + + http://www.simantics.org/Project-1.2/MainToolbarActionContext + + + + + diff --git a/bundles/org.simantics.desktop.ui/icons/appicon.png b/bundles/org.simantics.desktop.ui/icons/appicon.png new file mode 100644 index 000000000..1dee9e366 Binary files /dev/null and b/bundles/org.simantics.desktop.ui/icons/appicon.png differ diff --git a/bundles/org.simantics.desktop.ui/icons/simantics256.png b/bundles/org.simantics.desktop.ui/icons/simantics256.png new file mode 100644 index 000000000..17e9f21c0 Binary files /dev/null and b/bundles/org.simantics.desktop.ui/icons/simantics256.png differ diff --git a/bundles/org.simantics.desktop.ui/icons/simantics32.png b/bundles/org.simantics.desktop.ui/icons/simantics32.png new file mode 100644 index 000000000..04738fd82 Binary files /dev/null and b/bundles/org.simantics.desktop.ui/icons/simantics32.png differ diff --git a/bundles/org.simantics.desktop.ui/plugin.xml b/bundles/org.simantics.desktop.ui/plugin.xml new file mode 100644 index 000000000..a3df92f98 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/plugin.xml @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/Activator.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/Activator.java new file mode 100644 index 000000000..ed2301f81 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/Activator.java @@ -0,0 +1,50 @@ +package org.simantics.desktop.ui.internal; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.desktop.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/DesktopProjectFeature.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/DesktopProjectFeature.java new file mode 100644 index 000000000..ca638cec2 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/DesktopProjectFeature.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * 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.desktop.ui.internal; + +import org.simantics.project.ProjectKeys; +import org.simantics.project.exception.ProjectException; +import org.simantics.project.features.AbstractProjectFeature; + +public class DesktopProjectFeature extends AbstractProjectFeature { + + private static final String DEFAULT_PERSPECTIVE = "org.simantics.desktop.modelling.perspective"; + + @Override + public void configure() throws ProjectException { + + Object existing = getProjectElement().getHint(ProjectKeys.DEFAULT_PERSPECTIVE); + if(existing == null) + getProjectElement().setHint(ProjectKeys.DEFAULT_PERSPECTIVE, DEFAULT_PERSPECTIVE); + + } + + @Override + public void deconfigure() throws ProjectException { + + } + +} diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportModel.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportModel.java new file mode 100644 index 000000000..3cb96a680 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportModel.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.desktop.ui.internal; + +import java.util.Collection; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.simantics.Simantics; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.db.layer0.request.ProjectModels; +import org.simantics.modeling.ModelingUtils; +import org.simantics.utils.datastructures.hints.IHintContext; + +public class ExportModel extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + try { + + Resource lib = Simantics.sync(new UniqueRead() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + Collection models = graph.sync(new ProjectModels(Simantics.getProjectResource())); + if(models.size() == 1) return models.iterator().next(); + return null; + } + + }); + if(lib == null) return null; + + IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN); + context.setHint(SelectionHints.KEY_MAIN, lib); + + IStructuredSelection sel = new StructuredSelection(context); + ModelingUtils.openWizard(Display.getCurrent(), sel, "org.simantics.modeling.ui.modelExportWizard"); + } catch (DatabaseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + + } + +} diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportSharedLibrary.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportSharedLibrary.java new file mode 100644 index 000000000..cbc6d0663 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportSharedLibrary.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.desktop.ui.internal; + +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.simantics.Simantics; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.modeling.ModelingUtils; +import org.simantics.scl.runtime.tuple.Tuple0; +import org.simantics.utils.datastructures.hints.IHintContext; + +public class ExportSharedLibrary extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + try { + Resource lib = Simantics.sync(new UniqueRead() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + List ontologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); + if(ontologies.size() == 1) return ontologies.iterator().next(); + return null; + } + + }); + if(lib == null) return null; + + IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN); + context.setHint(SelectionHints.KEY_MAIN, lib); + + IStructuredSelection sel = new StructuredSelection(context); + ModelingUtils.openWizard(Display.getCurrent(), sel, "org.simantics.modeling.ui.sharedOntologyExportWizard"); + } catch (DatabaseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + + } + +} diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java new file mode 100644 index 000000000..42a21d76c --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.desktop.ui.internal; + +import java.io.File; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.DatabaseJob; +import org.simantics.modeling.ModelingUtils; + +public class ImportModel extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + // Get imported transferable graph file using FileDialog + Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText("Import Model"); + + String path = Activator.getDefault().getPreferenceStore().getString("IMPORT_MODEL_PATH"); + if(path.isEmpty() || !(new File(path).exists())){ + path = System.getProperty("user.dir"); + } + + fd.setFilterPath(path); + String[] filterExt = {"*.tg", "*.*"}; + fd.setFilterExtensions(filterExt); + final String selected = fd.open(); + if(selected == null) return null; + + Job job = new DatabaseJob("Import model") { + + @Override + protected IStatus run(IProgressMonitor monitor) { + ModelingUtils.importModel(selected); + return Status.OK_STATUS; + } + }; + + job.setUser(true); + job.schedule(); + + return null; + + } + +} diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportSharedLibrary.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportSharedLibrary.java new file mode 100644 index 000000000..f9015e830 --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportSharedLibrary.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.desktop.ui.internal; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.simantics.modeling.ModelingUtils; + +public class ImportSharedLibrary extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + IStructuredSelection sel = new StructuredSelection(); + ModelingUtils.openWizard(Display.getCurrent(), sel, "org.simantics.modeling.ui.sharedOntologyImportWizard"); + return null; + + } + +} diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/NewModel.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/NewModel.java new file mode 100644 index 000000000..d6236ec7e --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/NewModel.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.desktop.ui.internal; + + import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.simantics.DatabaseJob; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.Configuration; +import org.simantics.modeling.ModelingUtils; +import org.simantics.platform.ui.PlatformUIResource; +import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; +import org.simantics.spreadsheet.util.SpreadsheetUtils; + +public class NewModel extends AbstractHandler { + + public static Resource execute(WriteGraph graph) throws DatabaseException { + PlatformUIResource PLATFORM = PlatformUIResource.getInstance(graph); + return execute(graph, PLATFORM.Model, null); + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Job job = new DatabaseJob("Creating Model") { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + Simantics.sync(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + execute(graph); + } + }); + return Status.OK_STATUS; + } catch (DatabaseException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e); + } + } + }; + job.setUser(true); + job.schedule(); + return null; + } + + public static Resource execute(WriteGraph graph, Resource type, String name) throws DatabaseException { + Resource model = ModelingUtils.createModel(graph, type, name); + Resource conf = graph.syncRequest(new Configuration(model)); + + ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", ""); + ModelingUtils.createLocalLibrary(graph, model, "Library"); + + Resource book = SpreadsheetGraphUtils.createBook(graph, conf, "Book1"); + SpreadsheetUtils.createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 }); + SpreadsheetUtils.createSheet(graph, book, "Sheet2", new String[] { }, new int[] { 50 }); + SpreadsheetUtils.createSheet(graph, book, "Sheet3", new String[] { }, new int[] { 50 }); + + return model; + } + +} diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/StandardModelledView.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/StandardModelledView.java new file mode 100644 index 000000000..3b706730c --- /dev/null +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/StandardModelledView.java @@ -0,0 +1,14 @@ +package org.simantics.desktop.ui.internal; + +import org.simantics.selectionview.StandardPropertyPage; +import org.simantics.ui.workbench.IPropertyPage; +import org.simantics.views.swt.ModelledView; + +public class StandardModelledView extends ModelledView { + + @Override + protected IPropertyPage getPropertyPage() { + return new StandardPropertyPage(getSite()); + } + +} diff --git a/bundles/org.simantics.diagram.svg/.classpath b/bundles/org.simantics.diagram.svg/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.diagram.svg/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.diagram.svg/.project b/bundles/org.simantics.diagram.svg/.project new file mode 100644 index 000000000..30169e2f8 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/.project @@ -0,0 +1,28 @@ + + + org.simantics.diagram.svg + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.diagram.svg/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.diagram.svg/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.diagram.svg/META-INF/MANIFEST.MF b/bundles/org.simantics.diagram.svg/META-INF/MANIFEST.MF new file mode 100644 index 000000000..13a372c64 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Svg +Bundle-SymbolicName: org.simantics.diagram.svg +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.diagram.svg.Activator +Bundle-Vendor: VTT +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.simantics;bundle-version="1.0.0", + org.simantics.diagram;bundle-version="1.1.1", + org.simantics.diagram.ontology;bundle-version="2.2.0", + org.simantics.db.management;bundle-version="1.1.0", + org.simantics.structural.ontology;bundle-version="1.2.0", + org.simantics.structural2;bundle-version="1.1.1", + org.apache.batik;bundle-version="1.8.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Export-Package: org.simantics.diagram.svg.export diff --git a/bundles/org.simantics.diagram.svg/build.properties b/bundles/org.simantics.diagram.svg/build.properties new file mode 100644 index 000000000..6092d8910 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + scl/ diff --git a/bundles/org.simantics.diagram.svg/scl/Diagram/svg.scl b/bundles/org.simantics.diagram.svg/scl/Diagram/svg.scl new file mode 100644 index 000000000..1f6851642 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/scl/Diagram/svg.scl @@ -0,0 +1,8 @@ +import "Simantics/DB" + +importJava "org.simantics.diagram.svg.export.DiagramToSVG" where + diagramToSVG :: Resource -> String + @JavaName diagramToSVG + diagramToSVGdpi :: Resource -> Double -> String + @JavaName diagramToSVG + diagramToSVGsize :: Resource -> Integer -> Integer -> String \ No newline at end of file diff --git a/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/Activator.java b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/Activator.java new file mode 100644 index 000000000..b2607e8c3 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/Activator.java @@ -0,0 +1,50 @@ +package org.simantics.diagram.svg; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.diagram.svg"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java new file mode 100644 index 000000000..636a246c9 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java @@ -0,0 +1,216 @@ +package org.simantics.diagram.svg.export; + + +import java.awt.Point; +import java.util.concurrent.Semaphore; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.batik.svggen.SVGGraphics2D; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.ResourceArray; +import org.simantics.db.common.request.PossibleIndexRoot; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.diagram.elements.DiagramNodeUtil; +import org.simantics.diagram.export.ImagePrinter; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.g2d.canvas.impl.CanvasContext; +import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.StructuralVariables; +import org.simantics.utils.DataContainer; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.page.MarginUtils.Margins; +import org.simantics.utils.threads.ThreadUtils; +import org.simantics.utils.threads.WorkerThread; + + +public class DiagramToSVG { + + + public static String diagramToSVG(Resource diagram) { + + try { + ImagePrinter.ImageExportPlan exportPlan = new ImagePrinter.ImageExportPlan(); + exportPlan.margin = 0.05; + exportPlan.dpi = 96.0; + exportPlan.diagram = diagram; + return render(diagram,exportPlan); + } catch (Exception e) { + e.printStackTrace(); + return "error "+ e.getMessage(); + } + + + } + + public static String diagramToSVG(Resource diagram, int width, int height) { + + try { + ImagePrinter.ImageExportPlan exportPlan = new ImagePrinter.ImageExportPlan(); + exportPlan.margin = 0.05; + exportPlan.size = new Point(width, height); + exportPlan.diagram = diagram; + return render(diagram,exportPlan); + } catch (Exception e) { + e.printStackTrace(); + return "error "+ e.getMessage(); + } + + + } + + public static String diagramToSVG(Resource diagram, double dpi) { + + try { + ImagePrinter.ImageExportPlan exportPlan = new ImagePrinter.ImageExportPlan(); + exportPlan.margin = 0.05; + exportPlan.dpi = dpi; + exportPlan.diagram = diagram; + return render(diagram,exportPlan); + } catch (Exception e) { + e.printStackTrace(); + return "error "+ e.getMessage(); + } + + + } + + public static String diagramToSVG(Resource diagram, ImagePrinter.ImageExportPlan exportPlan, Margins margins, SVGGraphics2D svgGenerator) { + + try { + return render(diagram,exportPlan,margins,svgGenerator); + } catch (Exception e) { + e.printStackTrace(); + return "error "+ e.getMessage(); + } + + } + + private static String render(final Resource input, final ImagePrinter.ImageExportPlan exportPlan) throws Exception { + return render(input, exportPlan, null, SVGBuilder.defaultSVGGenerator()); + } + + private static String render(final Resource input, final ImagePrinter.ImageExportPlan exportPlan, Margins margins, SVGGraphics2D svgExporter) throws Exception { + Resource diagram = Simantics.getSession().syncRequest(new Read() { + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + if (graph.isInstanceOf(input, DIA.Diagram)) + return input; + StructuralResource2 SR = StructuralResource2.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + if (graph.isInstanceOf(input, SR.Composite)) { + Resource possibleDiagram = graph.getPossibleObject(input, MOD.CompositeToDiagram); + if (possibleDiagram != null) + return possibleDiagram; + for (Resource r : graph.getObjects(input, L0.ConsistsOf)) { + if (graph.isInstanceOf(r, SR.Composite)) { + possibleDiagram = graph.getPossibleObject(input, MOD.CompositeToDiagram); + if (possibleDiagram != null) + return possibleDiagram; + } + } + } + return null; + } + }); + if (diagram == null) + throw new DatabaseException("Input " + input + " cannot be resolved as diagram"); + + + + + final WorkerThread thread = new WorkerThread("Diagram Image Painter"); + thread.start(); + + final CanvasContext ctx = new CanvasContext(thread); + final AtomicReference sgProvider = new AtomicReference(); + final ISessionContext sessionContext = Simantics.getSessionContext(); + final DataContainer result = new DataContainer(null); + final DataContainer exception = new DataContainer(null); + try { + final Semaphore done = new Semaphore(0); + // IMPORTANT: Load diagram in a different thread than the canvas context thread! + ThreadUtils.getBlockingWorkExecutor().execute(new Runnable() { + @Override + public void run() { + try { + Pair modelAndRVI = sessionContext.getSession().syncRequest(new UniqueRead>() { + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + return new Pair( resolveModel(graph, exportPlan.diagram ), resolveRVI(graph, exportPlan.diagram) ); + } + }); + + ICanvasSceneGraphProvider provider = DiagramNodeUtil.loadSceneGraphProvider(ctx, modelAndRVI.first, exportPlan.diagram, modelAndRVI.second); + sgProvider.set( provider ); + + ThreadUtils.asyncExec(thread, new Runnable() { + @Override + public void run() { + try { + SVGBuilder chassis = margins != null ? + new SVGBuilder(exportPlan.dpi,exportPlan.size,margins) : + new SVGBuilder(exportPlan.dpi,exportPlan.size,exportPlan.margin); + + result.set(chassis.paint(ctx, svgExporter)); + } catch (Exception e) { + exception.set(e); + } finally { + done.release(); + } + } + }); + } catch (DatabaseException e) { + exception.set(e); + done.release(); + } catch (Throwable e) { + exception.set(new DatabaseException(e)); + done.release(); + } finally { + done.release(); + } + } + }); + + done.acquire(2); + if (exception.get() != null) + throw exception.get(); + return result.get(); + } finally { + if (sgProvider.get() != null) + sgProvider.get().dispose(); + ctx.dispose(); + } + } + + private static Resource resolveModel(ReadGraph graph, Resource diagram) throws DatabaseException { + ModelingResources mod = ModelingResources.getInstance(graph); + Resource composite = graph.getSingleObject(diagram, mod.DiagramToComposite); + Resource model = graph.syncRequest(new PossibleIndexRoot(composite)); + if (model == null) + throw new ValidationException("no model found for composite " + NameUtils.getSafeName(graph, composite)); + return model; + } + + + + private static String resolveRVI(ReadGraph graph, Resource diagram) throws DatabaseException { + ModelingResources mod = ModelingResources.getInstance(graph); + Resource composite = graph.getSingleObject(diagram, mod.DiagramToComposite); + final ResourceArray compositePath = StructuralVariables.getCompositeArray(graph, composite); + final ResourceArray variablePath = compositePath.removeFromBeginning(1); + return StructuralVariables.getRVI(graph, variablePath); + } + +} diff --git a/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/SVGBuilder.java b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/SVGBuilder.java new file mode 100644 index 000000000..4f2d79b45 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/SVGBuilder.java @@ -0,0 +1,189 @@ +package org.simantics.diagram.svg.export; + +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.io.StringWriter; +import java.util.UUID; + +import org.apache.batik.dom.GenericDOMImplementation; +import org.apache.batik.svggen.SVGGraphics2D; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.DiagramUtils; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.participant.TransformUtil; +import org.simantics.scenegraph.g2d.G2DRenderingHints; +import org.simantics.scenegraph.utils.QualityHints; +import org.simantics.utils.page.MarginUtils; +import org.simantics.utils.page.MarginUtils.Margin; +import org.simantics.utils.page.MarginUtils.Margins; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * org.simantics.diagram.export.ImageBuilder with SVG support + * + * @author Marko Luukkainen + * + */ +public class SVGBuilder { + Double dpi; + Point size; + double margin; + Margins margins; + + /** + * + * @param file File to write the image (optional) + * @param dpi Dots Per Inch + * @param size Image size in pixels + * @param margin percentage of image width for margins. 0.05 is 5%. + */ + public SVGBuilder(Double dpi, Point size, double margin) { + this.dpi = dpi; + this.size = size; + this.margin = Math.max(margin,0.0); + this.margins = null; + } + + /** + * + * @param file File to write the image (optional) + * @param dpi Dots Per Inch + * @param size Image size in pixels + * @param margins Margins + */ + public SVGBuilder(Double dpi, Point size, Margins margins) { + this.dpi = dpi; + this.size = size; + this.margin = 0.0; + this.margins = margins; + } + + public static SVGGraphics2D defaultSVGGenerator() { + DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); + + // Create an instance of org.w3c.dom.Document. + String svgNS = "http://www.w3.org/2000/svg"; + Document document = domImpl.createDocument(svgNS, "svg", null); + + // Create an instance of the SVG Generator. + SVGGraphics2D svgGenerator = new SVGGraphics2D(document); + svgGenerator.getGeneratorContext().setIDGenerator(new UniqueIDGenerator(UUID.randomUUID().toString())); + return svgGenerator; + } + + /** + * @param canvasContext + * the canvas context to paint + * @param writeResults + * true to actually write the resulting Image to the file. + */ + public String paint(ICanvasContext canvasContext) throws Exception { + return paint(canvasContext, defaultSVGGenerator()); + } + + /** + * @param canvasContext + * the canvas context to paint + * svgGenerator + * the svg generator to use + * @param writeResults + * true to actually write the resulting Image to the file. + */ + public String paint(ICanvasContext canvasContext, SVGGraphics2D svgGenerator) throws Exception { + + Graphics2D g2 = svgGenerator; + + IDiagram diagram = canvasContext.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); + Rectangle2D diagramRect = DiagramUtils.getContentRect(diagram); + + if (diagramRect == null) + diagramRect = new Rectangle2D.Double(0, 0, 100, 100); + + // add margins to content. + double off = Math.max(diagramRect.getWidth(), diagramRect.getHeight()) * margin*0.5; + diagramRect = new Rectangle2D.Double(diagramRect.getX() - off, diagramRect.getY() - off, diagramRect.getWidth() + off * 2.0, diagramRect.getHeight() + off * 2.0); + + if (margins != null) { + diagramRect = org.simantics.scenegraph.utils.GeometryUtils.expandRectangle(diagramRect, + margins.top.diagramAbsolute, + margins.bottom.diagramAbsolute, + margins.left.diagramAbsolute, + margins.right.diagramAbsolute + ); + } + + // Make sure the transformation is reset. + AffineTransform tr = new AffineTransform(); + + Rectangle2D controlArea; + if (dpi != null) { + double mmToInch = 1.0 / 25.4; + controlArea = new Rectangle2D.Double(0, 0, diagramRect.getWidth() * mmToInch * dpi, diagramRect.getHeight() * mmToInch * dpi); + + if (margins != null) { + double w = controlArea.getWidth(); + double h = controlArea.getHeight(); + controlArea = org.simantics.scenegraph.utils.GeometryUtils.expandRectangle(controlArea, + margins.top.controlAbsolute + margins.top.controlRelative * h, + margins.bottom.controlAbsolute + margins.bottom.controlRelative * h, + margins.left.controlAbsolute + margins.left.controlRelative * w, + margins.right.controlAbsolute + margins.right.controlRelative * w + ); + } + } else { + controlArea = new Rectangle2D.Double(0, 0, size.getX(), size.getY()); + if (margins != null) { + double w = controlArea.getWidth(); + double h = controlArea.getHeight(); + controlArea = org.simantics.scenegraph.utils.GeometryUtils.expandRectangle(controlArea, + -(margins.top.controlAbsolute + margins.top.controlRelative * h), + -(margins.bottom.controlAbsolute + margins.bottom.controlRelative * h), + -(margins.left.controlAbsolute + margins.left.controlRelative * w), + -(margins.right.controlAbsolute + margins.right.controlRelative * w) + ); + } + } + + canvasContext.getSingleItem(TransformUtil.class).fitArea(controlArea, diagramRect, MarginUtils.NO_MARGINS); + + float width = (float)controlArea.getWidth(); + float height = (float)controlArea.getHeight(); + + + QualityHints.HIGH_QUALITY_HINTS.setQuality(g2); + g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + + g2.setTransform(tr); + g2.setClip(new Rectangle2D.Double(0, 0, controlArea.getWidth(), controlArea.getHeight())); + + g2.setRenderingHint(G2DRenderingHints.KEY_CONTROL_BOUNDS, new Rectangle2D.Double(0, 0, controlArea.getWidth(), controlArea.getHeight())); + + if (canvasContext.isLocked()) + throw new IllegalStateException("cannot render image, canvas context is locked: " + canvasContext); + + canvasContext.getSceneGraph().render(g2); + + + + Element root = svgGenerator.getRoot(); + root.setAttributeNS(null, "viewBox", "0 0 " + width + " " + height); + root.setAttributeNS(null, "height", Float.toString(height)); + root.setAttributeNS(null, "width", Float.toString(width)); + + // Finally, stream out SVG to the standard output using + // UTF-8 encoding. + boolean useCSS = false; // we want to use CSS style attributes + StringWriter writer = new StringWriter(); + //svgGenerator.stream(writer, useCSS); + svgGenerator.stream(root,writer, useCSS, false); + return writer.toString(); + } +} diff --git a/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/UniqueIDGenerator.java b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/UniqueIDGenerator.java new file mode 100644 index 000000000..9bfb8c074 --- /dev/null +++ b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/UniqueIDGenerator.java @@ -0,0 +1,18 @@ +package org.simantics.diagram.svg.export; + +import org.apache.batik.svggen.SVGIDGenerator; + +public class UniqueIDGenerator extends SVGIDGenerator{ + + String overallId; + public UniqueIDGenerator(String overallId) { + super(); + this.overallId = overallId; + } + + @Override + public String generateID(String prefix) { + return super.generateID(overallId+prefix); + } + +} diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java new file mode 100644 index 000000000..085f38bb5 --- /dev/null +++ b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java @@ -0,0 +1,6 @@ +package org.simantics.document.server.io; + +public interface ITreeTableCell extends ITableCell { + + int getParent(); +} diff --git a/bundles/org.simantics.document.server/scl/Document/All.scl b/bundles/org.simantics.document.server/scl/Document/All.scl index 35ab38a80..53124fb46 100644 --- a/bundles/org.simantics.document.server/scl/Document/All.scl +++ b/bundles/org.simantics.document.server/scl/Document/All.scl @@ -14,6 +14,9 @@ importJava "org.simantics.document.server.io.IDocument" where importJava "org.simantics.document.server.io.ITableCell" where data ITableCell +importJava "org.simantics.document.server.io.ITreeTableCell" where + data ITreeTableCell + importJava "org.simantics.document.server.io.IFont" where data IFont @@ -56,9 +59,9 @@ importJava "org.simantics.document.server.io.CommandContextMutable" where data CommandContextMutable @JavaName putString - putString :: CommandContextMutable -> String -> String -> CommandContextMutable + putString :: CommandContextMutable -> String -> String -> CommandContextMutable - putValue :: CommandContextMutable -> String -> a -> CommandContextMutable + putValue :: CommandContextMutable -> String -> a -> CommandContextMutable importJava "org.simantics.document.server.io.CommandContextImpl" where diff --git a/bundles/org.simantics.help.base/.classpath b/bundles/org.simantics.help.base/.classpath new file mode 100644 index 000000000..6cf33fb32 --- /dev/null +++ b/bundles/org.simantics.help.base/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bundles/org.simantics.help.base/.project b/bundles/org.simantics.help.base/.project new file mode 100644 index 000000000..c27404d1b --- /dev/null +++ b/bundles/org.simantics.help.base/.project @@ -0,0 +1,28 @@ + + + org.simantics.help.base + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.help.base/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.help.base/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..11f6e462d --- /dev/null +++ b/bundles/org.simantics.help.base/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bundles/org.simantics.help.base/META-INF/MANIFEST.MF b/bundles/org.simantics.help.base/META-INF/MANIFEST.MF new file mode 100644 index 000000000..d9c6d4585 --- /dev/null +++ b/bundles/org.simantics.help.base/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Contributions for Eclipse Help System +Bundle-SymbolicName: org.simantics.help.base;singleton:=true +Bundle-Version: 1.18.3.qualifier +Bundle-Activator: org.simantics.help.base.internal.Activator +Bundle-Vendor: Semantum Oy +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.help.base, + org.apache.commons.logging;bundle-version="1.0.4", + org.bouncycastle;bundle-version="1.47.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: ., + xmpbox-1.8.10.jar, + jempbox-1.8.10.jar, + fontbox-1.8.10.jar, + pdfbox-1.8.10.jar diff --git a/bundles/org.simantics.help.base/build.properties b/bundles/org.simantics.help.base/build.properties new file mode 100644 index 000000000..7904aba26 --- /dev/null +++ b/bundles/org.simantics.help.base/build.properties @@ -0,0 +1,10 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + pdfbox-1.8.10.jar,\ + fontbox-1.8.10.jar,\ + jempbox-1.8.10.jar,\ + xmpbox-1.8.10.jar +source.. = src/ diff --git a/bundles/org.simantics.help.base/fontbox-1.8.10.jar b/bundles/org.simantics.help.base/fontbox-1.8.10.jar new file mode 100644 index 000000000..3284950c8 Binary files /dev/null and b/bundles/org.simantics.help.base/fontbox-1.8.10.jar differ diff --git a/bundles/org.simantics.help.base/jempbox-1.8.10.jar b/bundles/org.simantics.help.base/jempbox-1.8.10.jar new file mode 100644 index 000000000..48cc63375 Binary files /dev/null and b/bundles/org.simantics.help.base/jempbox-1.8.10.jar differ diff --git a/bundles/org.simantics.help.base/pdfbox-1.8.10-src.zip b/bundles/org.simantics.help.base/pdfbox-1.8.10-src.zip new file mode 100644 index 000000000..e05aa634b Binary files /dev/null and b/bundles/org.simantics.help.base/pdfbox-1.8.10-src.zip differ diff --git a/bundles/org.simantics.help.base/pdfbox-1.8.10.jar b/bundles/org.simantics.help.base/pdfbox-1.8.10.jar new file mode 100644 index 000000000..87bb9a704 Binary files /dev/null and b/bundles/org.simantics.help.base/pdfbox-1.8.10.jar differ diff --git a/bundles/org.simantics.help.base/plugin.xml b/bundles/org.simantics.help.base/plugin.xml new file mode 100644 index 000000000..2a8ba7c7d --- /dev/null +++ b/bundles/org.simantics.help.base/plugin.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/Activator.java b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/Activator.java new file mode 100644 index 000000000..a53e7ce0c --- /dev/null +++ b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/Activator.java @@ -0,0 +1,30 @@ +package org.simantics.help.base.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + } + +} diff --git a/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFSearchParticipant.java b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFSearchParticipant.java new file mode 100644 index 000000000..d630e113e --- /dev/null +++ b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFSearchParticipant.java @@ -0,0 +1,54 @@ +package org.simantics.help.base.internal; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLDecoder; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.help.search.IHelpSearchIndex; +import org.eclipse.help.search.ISearchDocument; +import org.eclipse.help.search.SearchParticipant; +import org.osgi.framework.Bundle; + +/** + * An abstract search participants for adding XML documents to the search index. Subclass it + * and implement or override protected methods to handle parsing of the document. + * + * @since 1.20.0 + */ +public class PDFSearchParticipant extends SearchParticipant { + + @Override + public IStatus addDocument(IHelpSearchIndex index, String pluginId, String name, URL url, String id, ISearchDocument doc) { + try { + //System.out.println("PDFSearchParticipant.addDocument(" + index + ", " + pluginId + ", " + name + ", " + url + ", " + id + ", " + doc + ")"); + Bundle bundle = Platform.getBundle(pluginId); + if (bundle == null) + return new Status(IStatus.ERROR, pluginId, "Failed to find bundle " + bundle + " from the platform."); + + // Need to decode path because it will fail to resolve if it contains %20 (=' '). + IPath path = new Path(URLDecoder.decode(name, "UTF-8")); + path = path.removeFirstSegments(1); + URL bundleUrl = FileLocator.find(bundle, path, null); + if (bundleUrl == null) + return new Status(IStatus.ERROR, pluginId, "Failed to find file " + name + " from bundle " + pluginId + "."); + + URL fileUrl = FileLocator.toFileURL(bundleUrl); + if (!fileUrl.getProtocol().equals("file")) + return new Status(IStatus.ERROR, pluginId, "Failed to make " + url + " available as a file"); + + File f = new File(URLDecoder.decode(fileUrl.getPath(), "UTF-8")).getCanonicalFile(); + PDFUtil.stripText(f, doc); + return Status.OK_STATUS; + } catch (IOException e) { + return new Status(IStatus.ERROR, pluginId, "Failed to strip text from PDF document " + url + ".", e); + } + } + +} diff --git a/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFUtil.java b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFUtil.java new file mode 100644 index 000000000..c12e56b4d --- /dev/null +++ b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFUtil.java @@ -0,0 +1,42 @@ +package org.simantics.help.base.internal; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import org.apache.pdfbox.cos.COSDocument; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDDocumentInformation; +import org.apache.pdfbox.util.PDFTextStripper; +import org.eclipse.help.search.ISearchDocument; + +/** + * @author Tuukka Lehtonen + */ +public class PDFUtil { + + public static void stripText(File fromPdf, ISearchDocument doc) throws IOException { + PDFParser parser = new PDFParser(new FileInputStream(fromPdf)); + parser.parse(); + + try (COSDocument cosDoc = parser.getDocument()) { + try (PDDocument pdDoc = new PDDocument(cosDoc)) { + int numPages = pdDoc.getNumberOfPages(); + PDFTextStripper stripper = new PDFTextStripper(); + stripper.setStartPage(1); + stripper.setEndPage(numPages); + String text = stripper.getText(pdDoc); + PDDocumentInformation docInfo = pdDoc.getDocumentInformation(); + String title = docInfo.getTitle(); + String subject = docInfo.getSubject(); + if (title != null) + doc.setTitle(title); + if (subject != null) + doc.setSummary(subject); + doc.addContents(text); + } + } + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.help.base/xmpbox-1.8.10.jar b/bundles/org.simantics.help.base/xmpbox-1.8.10.jar new file mode 100644 index 000000000..7a8a46594 Binary files /dev/null and b/bundles/org.simantics.help.base/xmpbox-1.8.10.jar differ diff --git a/bundles/org.simantics.help.core/.classpath b/bundles/org.simantics.help.core/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.help.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.help.core/.project b/bundles/org.simantics.help.core/.project new file mode 100644 index 000000000..e627b6c3f --- /dev/null +++ b/bundles/org.simantics.help.core/.project @@ -0,0 +1,28 @@ + + + org.simantics.help.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.help.core/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.help.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.help.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.help.core/META-INF/MANIFEST.MF b/bundles/org.simantics.help.core/META-INF/MANIFEST.MF new file mode 100644 index 000000000..dacb90faa --- /dev/null +++ b/bundles/org.simantics.help.core/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Help Core +Bundle-SymbolicName: org.simantics.help.core;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.help.core.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.simantics.help.ontology;bundle-version="1.0.0", + org.simantics.db, + org.simantics.modeling.ontology, + org.simantics.layer0;bundle-version="1.1.0", + org.eclipse.help, + org.simantics.modeling;bundle-version="1.1.1", + winterwell.markdown, + org.simantics, + org.simantics.document.base.ontology, + org.eclipse.mylyn.wikitext.core, + org.eclipse.mylyn.wikitext.mediawiki.core +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Export-Package: org.simantics.help.core diff --git a/bundles/org.simantics.help.core/build.properties b/bundles/org.simantics.help.core/build.properties new file mode 100644 index 000000000..4e3c13e70 --- /dev/null +++ b/bundles/org.simantics.help.core/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + scl/,\ + plugin.xml diff --git a/bundles/org.simantics.help.core/css/style.css b/bundles/org.simantics.help.core/css/style.css new file mode 100644 index 000000000..6d0f994ab --- /dev/null +++ b/bundles/org.simantics.help.core/css/style.css @@ -0,0 +1,107 @@ +body { + font-family: "Lucida Grande", "Lucida Grande", Verdana; + font-size:12px; + font-weight:normal; + color:#000000; + border-left: 2em solid #2b476f; + border-rigth: 2em hidden #2b476f; + padding-left: 1em; + padding-right: 1em;} + scrollbar-face-color:#006600; + scrollbar-highlight-color:#C0C0C0; + scrollbar-3dlight-color:#C0C0C0; + scrollbar-darkshadow-color:#000000; + scrollbar-shadow-color:#0F4966; + scrollbar-arrow-color:#FFFFFF; + scrollbar-track-color:#C0C0C0; + background-color: white; +} + +table { + border-collapse: collapse; + text-align: left; + vertical-align: center; +} + +caption { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + text-align: left; + font-style: italic; +} + +th { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + background-color: silver; + padding-left: 5px; + padding-right: 5px; +} + +td { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + padding-left: 5px; + padding-right: 5px; +} + +figure { + margin: 0; +} + +figcaption { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + text-align: left; + font-style: italic; +} + +h1 { + font-family: "Lucida Grande", Verdana; + font-size:35px; + color:#2b476f; +} + +h2 { + font-family: "Lucida Grande", Verdana; + font-size:20px; + color:#000000; +} + +h3 { + font-family: "Lucida Grande", Verdana; + font-size:16px; +} + +A:link, A:visited, A:active { + font-family: "Lucida Grande", Verdana; + font-size: inherit; + text-decoration: none; + font-weight:bold; + color:#2b476f; +} + +A:hover { + font-family: "Lucida Grande", Verdana; + text-decoration: none; + font-weight:bold; + color:#222299; + background-color:#C0C0C0 +} + +A[name]:hover { + font-family: "Lucida Grande", Verdana; + text-decoration: inherit; + font-weight: inherit; + color: inherit; + background-color: inherit +} + +.wikitable { + text-align: left; + border-collapse: collapse; +} + +.wikitable, .wikitable th, .wikitable td { + border: 1px solid black; +} diff --git a/bundles/org.simantics.help.core/plugin.xml b/bundles/org.simantics.help.core/plugin.xml new file mode 100644 index 000000000..af0a286ec --- /dev/null +++ b/bundles/org.simantics.help.core/plugin.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/bundles/org.simantics.help.core/scl/Simantics/Help.scl b/bundles/org.simantics.help.core/scl/Simantics/Help.scl new file mode 100644 index 000000000..d104a5050 --- /dev/null +++ b/bundles/org.simantics.help.core/scl/Simantics/Help.scl @@ -0,0 +1,27 @@ +import "URL" +import "Simantics/DB" +import "http://www.simantics.org/Help-1.0" as HELP + +importJava "org.simantics.help.core.HelpUtils" where + createHelpLibrary :: Resource -> Resource + createHelpTutorial :: Resource -> String -> Resource + clearHelpTocCache :: () -> () + saveHelpFileContents :: Resource -> String -> () + readHelpFileContents :: Resource -> String + markdownToHtml :: Resource -> String + getHelpBrowserUrl :: () -> URL + +createHelpLibraryAction :: Resource -> () +createHelpLibraryAction parent = do + syncWrite (\() -> createHelpLibrary parent) + () + +createHelpTutorialAction :: Resource -> () +createHelpTutorialAction parent = do + tutorialFiles = syncRead (\x -> objectsWithType parent L0.ConsistsOf HELP.TutorialFile) + fileName = if length tutorialFiles == 0 + then "Tutorial" + else do + "Tutorial " + (show (length tutorialFiles)) + syncWrite (\() -> createHelpTutorial parent fileName) + () \ No newline at end of file diff --git a/bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java b/bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java new file mode 100644 index 000000000..8a4f19999 --- /dev/null +++ b/bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java @@ -0,0 +1,80 @@ +package org.simantics.help.core; + +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.help.core"; //$NON-NLS-1$ + + public static final String HTML_FOLDER = "html"; + + // The shared instance + private static Activator plugin; + private static Path directory; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + Bundle bundle = context.getBundle(); + IPath path = Platform.getStateLocation(bundle); + Path p = Paths.get(path.toOSString()); + directory = p.resolve(HTML_FOLDER); + if (!Files.exists(directory)) + Files.createDirectories(directory); + + // Ensure that style.css is inside the html directory + Path css = directory.resolve("style.css"); + if (!Files.exists(css)) { + Files.createFile(css); + URL url = bundle.getEntry("css/style.css"); + Files.copy(url.openStream(), css, StandardCopyOption.REPLACE_EXISTING); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + public static Path getHtmlDirectory() { + return directory; + } + +} diff --git a/bundles/org.simantics.help.core/src/org/simantics/help/core/HelpUtils.java b/bundles/org.simantics.help.core/src/org/simantics/help/core/HelpUtils.java new file mode 100644 index 000000000..730fd4240 --- /dev/null +++ b/bundles/org.simantics.help.core/src/org/simantics/help/core/HelpUtils.java @@ -0,0 +1,337 @@ +package org.simantics.help.core; + +import java.io.IOException; +import java.io.StringWriter; +import java.net.URL; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import org.eclipse.mylyn.wikitext.core.parser.MarkupParser; +import org.eclipse.mylyn.wikitext.core.parser.builder.HtmlDocumentBuilder; +import org.eclipse.mylyn.wikitext.mediawiki.core.MediaWikiLanguage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.help.IWorkbenchHelpSystem; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.BindingException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.document.base.ontology.DocumentationResource; +import org.simantics.help.HelpResources; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingUtils; +import org.simantics.structural.stubs.StructuralResource2; + +import winterwell.markdown.pagemodel.MarkdownPage; + +public class HelpUtils { + + public static Resource createHelpLibrary(WriteGraph graph, Resource parent) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + HelpResources HELP = HelpResources.getInstance(graph); + Resource library = graph.newResource(); + graph.claim(library, L0.InstanceOf, null, HELP.HelpLibrary); + graph.addLiteral(library, L0.HasName, L0.NameOf, "Help Library", Bindings.STRING); + graph.claim(parent, L0.ConsistsOf, L0.PartOf, library); + return library; + } + + public static Resource createHelpTutorial(WriteGraph graph, Resource parent, String name) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + HelpResources HELP = HelpResources.getInstance(graph); + Resource tutorialFile = graph.newResource(); + graph.claim(tutorialFile, L0.InstanceOf, null, HELP.TutorialFile); + graph.addLiteral(tutorialFile, L0.HasName, L0.NameOf, name, Bindings.STRING); + graph.claim(parent, L0.ConsistsOf, L0.PartOf, tutorialFile); + return tutorialFile; + } + + public static List collectHelps(ReadGraph graph, Resource indexRoot) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + HelpResources HELP = HelpResources.getInstance(graph); + List tutorialFiles = ModelingUtils.searchByType(graph, indexRoot, HELP.TutorialFile); + if (tutorialFiles.isEmpty()) + return Collections.emptyList(); + List result = new ArrayList<>(tutorialFiles.size()); + for (Resource tutorialFile : tutorialFiles) { + StringBuilder sb = new StringBuilder(); + + htmlHead(sb, graph.getRelatedValue2(tutorialFile, L0.HasName, Bindings.STRING)); + sb.append(HelpUtils.markdownToHtml(graph, tutorialFile)); + htmlHeadClose(sb); + + String indexRootURI = graph.getURI(indexRoot); + String indexRootName = graph.getRelatedValue2(indexRoot, L0.HasName, Bindings.STRING); + String tutorialFileURI = graph.getURI(tutorialFile); + String suffix = tutorialFileURI.substring(indexRootURI.length()); + try { + if (suffix.startsWith("/")) + suffix = suffix.substring(1); + suffix = URLDecoder.decode(suffix, StandardCharsets.UTF_8.name()); + Path outputPath = Activator.getHtmlDirectory().resolve(indexRootName).resolve(suffix + ".html"); + createDirsRec(outputPath.getParent()); + if (!Files.exists(outputPath)) + Files.createFile(outputPath); + Files.write(outputPath, sb.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); + result.add(outputPath); + } catch (IOException e) { + e.printStackTrace(); + } + } + return result; + } + + private static void createDirsRec(Path path) throws IOException { + Path parent = path.getParent(); + if (!Files.exists(parent)) { + createDirsRec(parent); + } + if (!Files.exists(path)) + Files.createDirectory(path); + } + + public static Map> collectHelpsFromSharedLibraries(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Collection sharedLibraries = graph.syncRequest(new ObjectsWithType(graph.getRootLibrary(), L0.ConsistsOf, L0.SharedOntology)); + if (sharedLibraries.isEmpty()) + return Collections.emptyMap(); + Map> result = new HashMap<>(sharedLibraries.size()); + for (Resource library : sharedLibraries) { + String libraryName = graph.getRelatedValue2(library, L0.HasName, Bindings.STRING); + List paths = collectHelps(graph, library); + result.put(libraryName, paths); + } + return result; + } + + public static Map collectWidgetReferencesFromSharedLibraries(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Collection sharedLibraries = graph.syncRequest(new ObjectsWithType(graph.getRootLibrary(), L0.ConsistsOf, L0.SharedOntology)); + if (sharedLibraries.isEmpty()) + return Collections.emptyMap(); + Map result = new HashMap<>(sharedLibraries.size()); + for (Resource library : sharedLibraries) { + String html = createWidgetReference(graph, library, "Widget Reference"); + String indexRootName = graph.getRelatedValue2(library, L0.HasName, Bindings.STRING); + try { + Path outputPath = Activator.getHtmlDirectory().resolve(indexRootName).resolve("widgetReference.html"); + createDirsRec(outputPath.getParent()); + if (!Files.exists(outputPath)) + Files.createFile(outputPath); + Files.write(outputPath, html.getBytes(StandardCharsets.UTF_8), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); + result.put(indexRootName, outputPath); + } catch (IOException e) { + e.printStackTrace(); + } + } + return result; + } + + private static void htmlHead(StringBuilder sb, String title) { + sb.append("\n"); + sb.append("" + title + " Tutorial\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("

" + title + "

\n"); + sb.append("
\n"); + } + + private static void htmlHeadClose(StringBuilder sb) { + sb.append("\n"); + } + + public static String createWidgetReference(ReadGraph graph, Resource indexRoot, String title) throws DatabaseException { + + String ontologyDesc = NameUtils.getSafeLabel(graph, indexRoot); + + StringBuilder sb = new StringBuilder(); + + sb.append("\n"); + sb.append("" + ontologyDesc+ " Widget Reference\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("

" + ontologyDesc+ "

\n"); + sb.append("

Widget Reference

\n"); + sb.append("
\n"); + sb.append("

" + title + "

\n"); + + Layer0 L0 = Layer0.getInstance(graph); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + DocumentationResource DOC = DocumentationResource.getInstance(graph); + + List types = ModelingUtils.searchByType(graph, indexRoot, DOC.DocumentComponentType); + for(Resource type : types) { + + + String label = NameUtils.getSafeLabel(graph, type); + + sb.append("

" + label + "

\n"); + sb.append("

Description

\n"); + + String desc = graph.getPossibleRelatedValue(type, L0.HasDescription); + if(desc == null) desc = ""; + + sb.append("

" + WikiParser.parseToHtml(desc, false) + "

\n"); + + sb.append("

Base Types

\n"); + + Map names = new HashMap(); + + for(Resource r : graph.getSupertypes(type)) { + + if(graph.isInheritedFrom(r, STR.Component)) { + + String label2 = NameUtils.getSafeLabel(graph, r); + String name = graph.getRelatedValue(r, L0.HasName); + //if("Component".equals(name)) continue; + if("Element".equals(name)) continue; + if("DefinedElement".equals(name)) continue; + if("PrimitiveComponent".equals(name)) continue; + if("DocumentComponent".equals(name)) continue; + + names.put(name, label2); + + } + + } + + for(Map.Entry entry : names.entrySet()) { + String stuff = "predefined/baseWidgets.html#"; + sb.append("" + entry.getValue() + "\n"); + //sb.append("" + entry.getValue() + "\n"); + } + + sb.append("

Properties

\n"); + sb.append("\n"); + sb.append("\n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + + Map propertyMap = new TreeMap(); + + for(Resource ass : graph.getObjects(type, L0.Asserts)) { + + Resource object = graph.getSingleObject(ass, L0.HasObject); + + if(graph.isInstanceOf(object, L0.SCLValue)) continue; + if(graph.isInstanceOf(object, L0.Function)) continue; + if(graph.isInstanceOf(object, L0.ExternalValue)) continue; + + Resource pred = graph.getSingleObject(ass, L0.HasPredicate); + String pName = NameUtils.getSafeLabel(graph, pred); + propertyMap.put(pName, ass); + } + + for (Entry entry : propertyMap.entrySet()) { + Resource ass = entry.getValue(); + Resource object = graph.getSingleObject(ass, L0.HasObject); + + Resource pred = graph.getSingleObject(ass, L0.HasPredicate); + String pName = NameUtils.getSafeLabel(graph, pred); + String valueType = graph.getPossibleRelatedValue(pred, L0.RequiresValueType); + + Object jObject = graph.getValue(object); + String objectName = jObject.toString(); + if(jObject.getClass().isArray()) { + Class c1 = jObject.getClass().getComponentType(); + boolean p1 = c1.isPrimitive(); + if (!p1) + objectName = Arrays.toString((Object[])jObject); + if (boolean.class.equals(c1)) + objectName = Arrays.toString((boolean[])jObject); + else if (byte.class.equals(c1)) + objectName = Arrays.toString((byte[])jObject); + else if (int.class.equals(c1)) + objectName = Arrays.toString((int[])jObject); + else if (long.class.equals(c1)) + objectName = Arrays.toString((long[])jObject); + else if (float.class.equals(c1)) + objectName = Arrays.toString((float[])jObject); + else if (double.class.equals(c1)) + objectName = Arrays.toString((double[])jObject); + } + + String pDesc = graph.getPossibleRelatedValue(pred, L0.HasDescription); + if(pDesc == null) pDesc = ""; + + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + } + + sb.append("

Property Name

Type

Default Value

Description
" + pName + "" + valueType + "" + objectName + "" + WikiParser.parseToHtml(pDesc, false) + "

\n"); + } + + sb.append("\n"); + return sb.toString(); + } + + public static void clearHelpTocCache() { + SimanticsTocProvider.clearTocCache(); + } + + public static void saveHelpFileContents(WriteGraph graph, Resource helpFile, String currentText) throws BindingException, ManyObjectsForFunctionalRelationException, ServiceException { + HelpResources HELP = HelpResources.getInstance(graph); + graph.claimLiteral(helpFile, HELP.HelpFile_contents, currentText, Bindings.STRING); + } + + public static String readHelpFileContents(ReadGraph graph, Resource helpFile) throws DatabaseException { + HelpResources HELP = HelpResources.getInstance(graph); + String content = graph.getPossibleRelatedValue2(helpFile, HELP.HelpFile_contents, Bindings.STRING); + return content != null ? content : ""; + } + + public static String markdownToHtml(ReadGraph graph, Resource tutorialFile) throws DatabaseException { + HelpResources HELP = HelpResources.getInstance(graph); + String markdown = graph.getRelatedValue2(tutorialFile, HELP.HelpFile_contents, Bindings.STRING); + MarkdownPage page = new MarkdownPage(markdown); + return page.html(); + } + + public static URL getHelpBrowserUrl() { + IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); + URL url = helpSystem.resolve("", false); + return url; + } + + private static class WikiParser { + + private static MarkupParser markupParser = new MarkupParser(new MediaWikiLanguage()); + + private WikiParser() {} + + public static String parseToHtml(String wiki, boolean asDocument) { + StringWriter writer = new StringWriter(); + HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer); + markupParser.setBuilder(builder); + markupParser.parse(wiki, asDocument); + return writer.toString(); + } + } +} diff --git a/bundles/org.simantics.help.core/src/org/simantics/help/core/SimanticsTocProvider.java b/bundles/org.simantics.help.core/src/org/simantics/help/core/SimanticsTocProvider.java new file mode 100644 index 000000000..559ef55ea --- /dev/null +++ b/bundles/org.simantics.help.core/src/org/simantics/help/core/SimanticsTocProvider.java @@ -0,0 +1,168 @@ +package org.simantics.help.core; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.help.AbstractTocProvider; +import org.eclipse.help.ITocContribution; +import org.eclipse.help.internal.HelpPlugin; +import org.eclipse.help.internal.Topic; +import org.eclipse.help.internal.entityresolver.LocalEntityResolver; +import org.eclipse.help.internal.toc.Toc; +import org.eclipse.help.internal.toc.TocContribution; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +@SuppressWarnings("restriction") +public class SimanticsTocProvider extends AbstractTocProvider { + + private static DocumentBuilder builder; + private static Document document; + + private static Map widgetReferences; + private static Map> tutorials; + + @Override + public ITocContribution[] getTocContributions(String locale) { + List contributions = new ArrayList<>(); + + if (widgetReferences == null || tutorials == null) { + try { + Simantics.getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + widgetReferences = HelpUtils.collectWidgetReferencesFromSharedLibraries(graph); + tutorials = HelpUtils.collectHelpsFromSharedLibraries(graph); + + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + Map tocs = new HashMap<>(); + + if (widgetReferences != null) { + for (Map.Entry widgetReference : widgetReferences.entrySet()) { + String libName = widgetReference.getKey(); + Path htmlFile = widgetReference.getValue(); + Toc toc = tocs.get(libName); + if (toc == null) { + Element element = getDocument().createElement("toc"); + toc = new Toc(element); + toc.setLabel(libName); +// toc.setTopic(libName); +// toc.setHref(libName); + tocs.put(libName, toc); + } + + Topic topic = new Topic(); + //topic.setLabel(htmlFile.getFileName().toString()); + topic.setLabel("Widget Reference"); +// String href = htmlFile.toUri().toString(); + String href = htmlFile.toString().split(Activator.PLUGIN_ID)[1].substring(1); + href = "PLUGINS_ROOT/platform:/meta/" + Activator.PLUGIN_ID + "/" + href; + topic.setHref(href.replace("\\", "/").replace(" ", "%20")); + + toc.appendChild(topic); + } + } + + if (tutorials != null) { + for (Map.Entry> tutorial : tutorials.entrySet()) { + String libName = tutorial.getKey(); + Toc toc = tocs.get(libName); + if (toc == null) { + Element element = getDocument().createElement("toc"); + toc = new Toc(element); + toc.setLabel(libName); + toc.setTopic(libName); + toc.setHref(libName); + tocs.put(libName, toc); + } + + Map topics = new HashMap<>(); + + for (Path htmlFile : tutorial.getValue()) { + Path path = Paths.get(htmlFile.toString().split(libName)[1]); + Topic topic = getOrCreateTopic(topics, toc, path); + String href = htmlFile.toString().split(Activator.PLUGIN_ID)[1].substring(1); + href = "PLUGINS_ROOT/platform:/meta/" + Activator.PLUGIN_ID + "/" + href; +// String href = htmlFile.toUri().toString(); + topic.setHref(href.replace("\\", "/").replace(" ", "%20")); + } + } + } + + for (Toc toc : tocs.values()) { + TocContribution contribution = new TocContribution(); + contribution.setLocale(locale); + contribution.setId(toc.getLabel()); + contribution.setCategoryId("category_" + toc.getLabel()); + contribution.setPrimary(true); + contribution.setContributorId(Activator.PLUGIN_ID); + + contribution.setToc(toc); + contributions.add(contribution); + } + + + return (ITocContribution[])contributions.toArray(new ITocContribution[contributions.size()]); + } + + private static Topic getOrCreateTopic(Map topics, Toc toc, Path topicPath) { + String topicName = topicPath.getFileName().toString(); + Topic topic = topics.get(topicName); + if (topic == null) { + topic = new Topic(); + topic.setLabel(topicName); + Path parentPath = topicPath.getParent(); + if (parentPath != null && parentPath.getFileName() != null) { + Topic parentTopic = getOrCreateTopic(topics, toc, parentPath); + parentTopic.appendChild(topic); + } else { + toc.appendChild(topic); + } + topics.put(topicName, topic); + } + return topic; + } + + private static Document getDocument() { + if (document == null) { + if (builder == null) { + try { + builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + builder.setEntityResolver(new LocalEntityResolver()); + } + catch (ParserConfigurationException e) { + String msg = "Error creating document builder"; //$NON-NLS-1$ + HelpPlugin.logError(msg, e); + } + } + document = builder.newDocument(); + } + return document; + } + + public static void clearTocCache() { + widgetReferences.clear(); + widgetReferences = null; + tutorials.clear(); + tutorials = null; + HelpPlugin.getTocManager().clearCache(); + } +} diff --git a/bundles/org.simantics.help.feature/.project b/bundles/org.simantics.help.feature/.project new file mode 100644 index 000000000..5f32fab93 --- /dev/null +++ b/bundles/org.simantics.help.feature/.project @@ -0,0 +1,17 @@ + + + org.simantics.help.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/bundles/org.simantics.help.feature/build.properties b/bundles/org.simantics.help.feature/build.properties new file mode 100644 index 000000000..0c85ae77c --- /dev/null +++ b/bundles/org.simantics.help.feature/build.properties @@ -0,0 +1,12 @@ +############################################################################### +# 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 +############################################################################### +bin.includes = feature.xml diff --git a/bundles/org.simantics.help.feature/feature.xml b/bundles/org.simantics.help.feature/feature.xml new file mode 100644 index 000000000..24eaf0902 --- /dev/null +++ b/bundles/org.simantics.help.feature/feature.xml @@ -0,0 +1,209 @@ + + + + + + This feature gather together the parts of Eclipse SDK that are needed to use the Eclipse help system and cheat sheets. + + + + Licensed under Eclipse Public License (EPL) 1.0. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.simantics.help.files/.project b/bundles/org.simantics.help.files/.project new file mode 100644 index 000000000..9b0302960 --- /dev/null +++ b/bundles/org.simantics.help.files/.project @@ -0,0 +1,22 @@ + + + org.simantics.help.files + + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + + diff --git a/bundles/org.simantics.help.files/META-INF/MANIFEST.MF b/bundles/org.simantics.help.files/META-INF/MANIFEST.MF new file mode 100644 index 000000000..61896e169 --- /dev/null +++ b/bundles/org.simantics.help.files/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Help Files Location +Bundle-SymbolicName: org.simantics.help.files +Bundle-Version: 1.0.0.qualifier diff --git a/bundles/org.simantics.help.files/build.properties b/bundles/org.simantics.help.files/build.properties new file mode 100644 index 000000000..5e3728557 --- /dev/null +++ b/bundles/org.simantics.help.files/build.properties @@ -0,0 +1 @@ +bin.includes = META-INF/ diff --git a/bundles/org.simantics.help.files/html/style.css b/bundles/org.simantics.help.files/html/style.css new file mode 100644 index 000000000..6d0f994ab --- /dev/null +++ b/bundles/org.simantics.help.files/html/style.css @@ -0,0 +1,107 @@ +body { + font-family: "Lucida Grande", "Lucida Grande", Verdana; + font-size:12px; + font-weight:normal; + color:#000000; + border-left: 2em solid #2b476f; + border-rigth: 2em hidden #2b476f; + padding-left: 1em; + padding-right: 1em;} + scrollbar-face-color:#006600; + scrollbar-highlight-color:#C0C0C0; + scrollbar-3dlight-color:#C0C0C0; + scrollbar-darkshadow-color:#000000; + scrollbar-shadow-color:#0F4966; + scrollbar-arrow-color:#FFFFFF; + scrollbar-track-color:#C0C0C0; + background-color: white; +} + +table { + border-collapse: collapse; + text-align: left; + vertical-align: center; +} + +caption { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + text-align: left; + font-style: italic; +} + +th { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + background-color: silver; + padding-left: 5px; + padding-right: 5px; +} + +td { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + padding-left: 5px; + padding-right: 5px; +} + +figure { + margin: 0; +} + +figcaption { + font-family: "Lucida Grande", Verdana; + font-size: 12px; + text-align: left; + font-style: italic; +} + +h1 { + font-family: "Lucida Grande", Verdana; + font-size:35px; + color:#2b476f; +} + +h2 { + font-family: "Lucida Grande", Verdana; + font-size:20px; + color:#000000; +} + +h3 { + font-family: "Lucida Grande", Verdana; + font-size:16px; +} + +A:link, A:visited, A:active { + font-family: "Lucida Grande", Verdana; + font-size: inherit; + text-decoration: none; + font-weight:bold; + color:#2b476f; +} + +A:hover { + font-family: "Lucida Grande", Verdana; + text-decoration: none; + font-weight:bold; + color:#222299; + background-color:#C0C0C0 +} + +A[name]:hover { + font-family: "Lucida Grande", Verdana; + text-decoration: inherit; + font-weight: inherit; + color: inherit; + background-color: inherit +} + +.wikitable { + text-align: left; + border-collapse: collapse; +} + +.wikitable, .wikitable th, .wikitable td { + border: 1px solid black; +} diff --git a/bundles/org.simantics.help.ontology/.classpath b/bundles/org.simantics.help.ontology/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.help.ontology/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.help.ontology/.project b/bundles/org.simantics.help.ontology/.project new file mode 100644 index 000000000..1ddcb8d8c --- /dev/null +++ b/bundles/org.simantics.help.ontology/.project @@ -0,0 +1,34 @@ + + + org.simantics.help.ontology + + + + + + org.simantics.graph.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.simantics.graph.nature + + diff --git a/bundles/org.simantics.help.ontology/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.help.ontology/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.help.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.help.ontology/META-INF/MANIFEST.MF b/bundles/org.simantics.help.ontology/META-INF/MANIFEST.MF new file mode 100644 index 000000000..c2a6f1c0b --- /dev/null +++ b/bundles/org.simantics.help.ontology/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Help Ontology +Bundle-SymbolicName: org.simantics.help.ontology +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.simantics.layer0, + org.simantics.viewpoint.ontology;bundle-version="1.2.0", + org.simantics.modeling.ontology;bundle-version="1.2.0", + org.simantics.silk.ontology;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.simantics.help diff --git a/bundles/org.simantics.help.ontology/build.properties b/bundles/org.simantics.help.ontology/build.properties new file mode 100644 index 000000000..022de1735 --- /dev/null +++ b/bundles/org.simantics.help.ontology/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + graph.tg diff --git a/bundles/org.simantics.help.ontology/graph.tg b/bundles/org.simantics.help.ontology/graph.tg new file mode 100644 index 000000000..4cb13d035 Binary files /dev/null and b/bundles/org.simantics.help.ontology/graph.tg differ diff --git a/bundles/org.simantics.help.ontology/graph/Help.pgraph b/bundles/org.simantics.help.ontology/graph/Help.pgraph new file mode 100644 index 000000000..ac5a9a45b --- /dev/null +++ b/bundles/org.simantics.help.ontology/graph/Help.pgraph @@ -0,0 +1,57 @@ +L0 = +VP = +MOD = +SILK = + +HELP = : L0.Ontology + @L0.new + L0.HasResourceClass "org.simantics.help.HelpResources" + +HELP.SCLMain : L0.SCLModule + L0.SCLModule.definition _ : L0.String + @L0.loadString "scl/SCLMain.scl" + +HELP.HelpLibrary -- HELP.HelpFile.contents --> L0.String () { + public HelpResources perform(ReadGraph graph) throws DatabaseException { + QueryControl qc = graph.getService(QueryControl.class); + return new HelpResources(qc.getIndependentGraph(graph)); + } + }); + session.registerService(HelpResources.class, ret); + } + return ret; + } + +} + diff --git a/bundles/org.simantics.help.ui/.classpath b/bundles/org.simantics.help.ui/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.help.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.help.ui/.project b/bundles/org.simantics.help.ui/.project new file mode 100644 index 000000000..25dbe7a46 --- /dev/null +++ b/bundles/org.simantics.help.ui/.project @@ -0,0 +1,28 @@ + + + org.simantics.help.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.help.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.help.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.help.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.help.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.help.ui/META-INF/MANIFEST.MF new file mode 100644 index 000000000..e9f8ba1b9 --- /dev/null +++ b/bundles/org.simantics.help.ui/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Help UI +Bundle-SymbolicName: org.simantics.help.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.help.ui.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.simantics.ui, + org.simantics.help.ontology, + winterwell.markdown;bundle-version="1.2.0", + org.eclipse.ui.editors;bundle-version="3.9.0", + org.eclipse.jface.text;bundle-version="3.10.0", + org.eclipse.core.resources;bundle-version="3.10.1", + org.simantics.help.core +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: . diff --git a/bundles/org.simantics.help.ui/build.properties b/bundles/org.simantics.help.ui/build.properties new file mode 100644 index 000000000..6f20375d6 --- /dev/null +++ b/bundles/org.simantics.help.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/org.simantics.help.ui/plugin.xml b/bundles/org.simantics.help.ui/plugin.xml new file mode 100644 index 000000000..d5ffa052c --- /dev/null +++ b/bundles/org.simantics.help.ui/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + diff --git a/bundles/org.simantics.help.ui/src/org/simantics/help/ui/Activator.java b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/Activator.java new file mode 100644 index 000000000..2a38479bd --- /dev/null +++ b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/Activator.java @@ -0,0 +1,50 @@ +package org.simantics.help.ui; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.help.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/bundles/org.simantics.help.ui/src/org/simantics/help/ui/HelpFileDocumentProvider.java b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/HelpFileDocumentProvider.java new file mode 100644 index 000000000..d199490f8 --- /dev/null +++ b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/HelpFileDocumentProvider.java @@ -0,0 +1,94 @@ +package org.simantics.help.ui; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.ui.texteditor.AbstractDocumentProvider; +import org.simantics.Simantics; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.help.core.HelpUtils; +import org.simantics.layer0.Layer0; +import org.simantics.ui.workbench.IResourceEditorInput; +import org.simantics.utils.logging.TimeLogger; + +public class HelpFileDocumentProvider extends AbstractDocumentProvider { + + private Resource resource; + private String currentText; + private boolean errorHappened; + + @Override + protected IDocument createDocument(Object element) throws CoreException { + IResourceEditorInput input = (IResourceEditorInput) element; + resource = input.getResource(); + try { + return Simantics.getSession().syncRequest(new UniqueRead() { + @Override + public Document perform(ReadGraph graph) throws DatabaseException { + currentText = HelpUtils.readHelpFileContents(graph, resource); + errorHappened = false; + return new Document(currentText != null ? currentText : ""); + } + }); + } catch (DatabaseException e) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + errorHappened = true; + return new Document(sw.toString()); + } + } + + @Override + protected IAnnotationModel createAnnotationModel(Object element) throws CoreException { + return null; + } + + @Override + protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException { + TimeLogger.resetTimeAndLog("HelpFileDocumentProvider.doSaveDocument"); + currentText = document.get(); + Simantics.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + HelpUtils.saveHelpFileContents(graph, resource, currentText); + Layer0Utils.addCommentMetadata(graph, "Saved SCL Module " + graph.getRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING)); + } + }); + } + + @Override + protected IRunnableContext getOperationRunner(IProgressMonitor monitor) { + return null; + } + + @Override + public boolean isModifiable(Object element) { + return !errorHappened; + } + + @Override + public boolean isReadOnly(Object element) { + return errorHappened; + } + + @Override + public boolean canSaveDocument(Object element) { + return !errorHappened && !getDocument(element).get().equals(currentText); + } + +} diff --git a/bundles/org.simantics.help.ui/src/org/simantics/help/ui/HelpFileEditor.java b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/HelpFileEditor.java new file mode 100644 index 000000000..2b5eacade --- /dev/null +++ b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/HelpFileEditor.java @@ -0,0 +1,93 @@ +package org.simantics.help.ui; + +import java.util.function.Supplier; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.simantics.Simantics; +import org.simantics.db.Session; +import org.simantics.db.common.request.ParametrizedRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.combinations.Combinators; +import org.simantics.ui.workbench.IResourceEditorInput; +import org.simantics.ui.workbench.ResourceEditorSupport; +import org.simantics.ui.workbench.TitleUpdater; +import org.simantics.ui.workbench.TitleWithParentNameRequest; +import org.simantics.ui.workbench.ToolTipRequest; +import org.simantics.ui.workbench.editor.input.InputValidationCombinators; + +import winterwell.markdown.editors.MarkdownEditor; + +public class HelpFileEditor extends MarkdownEditor { + + private static final String EDITOR_ID = "org.simantics.help.ui.HelpFileEditor"; + + private boolean disposed; + + private static final ParametrizedRead INPUT_VALIDATOR = + Combinators.compose(InputValidationCombinators.hasURI(), InputValidationCombinators.extractInputResource()); + + private ResourceEditorSupport support; + + public HelpFileEditor() { + super(); + setDocumentProvider(new HelpFileDocumentProvider()); + } + + @Override + public void init(IEditorSite site, IEditorInput input) throws PartInitException { + super.init(site, input); + + support = new ResourceEditorSupport(this, INPUT_VALIDATOR); + support.activateValidation(); + try { + getResourceInput().init(null); + } catch (DatabaseException e) { + throw new PartInitException("Failed to initialize " + input, e); + } + + } + + protected IResourceEditorInput getResourceInput() { + return (IResourceEditorInput) getEditorInput(); + } + + @Override + public void createPartControl(Composite parent) { + super.createPartControl(parent); + updatePartName(); + } + + protected void updatePartName() { + setPartName(getEditorInput().getName()); + + Session session = Simantics.peekSession(); + if (session != null) { + Supplier disposedCallback = this::isDisposed; + session.asyncRequest(new TitleWithParentNameRequest(getResourceInput()), + new TitleUpdater(getSite().getShell().getDisplay(), this::setPartName, disposedCallback)); + session.asyncRequest(new ToolTipRequest(getSite().getId(), getResourceInput()), + new TitleUpdater(getSite().getShell().getDisplay(), this::setTitleToolTip, disposedCallback)); + } + } + + @Override + public void dispose() { + disposed = true; + if (support != null) { + support.dispose(); + support = null; + } + super.dispose(); + } + + public boolean isDisposed() { + return disposed; + } + + public static String getEditorId() { + return EDITOR_ID; + } +} diff --git a/bundles/org.simantics.help.ui/src/org/simantics/help/ui/OpenHelpFileAdapter.java b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/OpenHelpFileAdapter.java new file mode 100644 index 000000000..c5847ce0d --- /dev/null +++ b/bundles/org.simantics.help.ui/src/org/simantics/help/ui/OpenHelpFileAdapter.java @@ -0,0 +1,60 @@ +package org.simantics.help.ui; + +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.simantics.Logger; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleIndexRoot; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.RVI; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.help.HelpResources; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class OpenHelpFileAdapter extends AbstractResourceEditorAdapter { + + public OpenHelpFileAdapter() { + super("Help File Editor"); + } + + protected String getEditorId() { + return HelpFileEditor.getEditorId(); + } + + @Override + protected boolean canHandle(ReadGraph g, Resource input) throws DatabaseException { + return g.isInstanceOf(input, HelpResources.getInstance(g).HelpFile); + } + + @Override + protected void openEditor(Resource input) throws Exception { + Simantics.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + + Variable variable = Variables.getVariable(g, input); + final Resource model = g.syncRequest(new PossibleIndexRoot(input)); + final RVI rvi = variable.getPossibleRVI(g); + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + try { + String editorId = getEditorId(); + WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, input, model, rvi)); + } catch (PartInitException e) { + Logger.defaultLogError(e); + } + } + }); + } + }); + } + +} diff --git a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl index e91b7d786..ac50e3e73 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl @@ -86,6 +86,9 @@ importJava "org.simantics.db.ReadGraph" where getDataType :: Resource -> Datatype + @JavaName getSupertypes + superTypesOf :: Resource -> Set.T Resource + @private @JavaName getURI uriOfResource :: Resource -> String diff --git a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl index c54048a73..bcfd43a64 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl @@ -119,6 +119,10 @@ importJava "org.simantics.db.layer0.variable.Variable" where @JavaName getProperties properties_ :: Variable -> Collection Variable + + @JavaName getProperties + propertiesClassified_ :: Variable -> Resource -> Collection Variable + @JavaName getChildren children_ :: Variable -> Collection Variable @@ -420,4 +424,8 @@ instance Browsable Variable where valueOf v = untypedValue v variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic) child = child_ - possibleChild = possibleChild_ \ No newline at end of file + possibleChild = possibleChild_ + +propertiesClassified :: Variable -> Resource -> [Variable] +propertiesClassified parent classified = do + collectionToList $ propertiesClassified_ parent classified \ No newline at end of file diff --git a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java new file mode 100644 index 000000000..0ff973e9d --- /dev/null +++ b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 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 THTH Simantics + * Division Member Component License which accompanies this + * distribution, and is available at + * http://www.simantics.org/legal/sdmcl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.spreadsheet.common; + +import org.simantics.document.server.io.ITreeTableCell; + +public class TreeTableCell extends TableCell implements ITreeTableCell { + + private int parent = -1; + + public TreeTableCell() { + } + + public void setParent(int parent) { + this.parent = parent; + } + + @Override + public int getParent() { + return parent; + } + +} diff --git a/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl b/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl index cb35884c7..4eeb308d2 100644 --- a/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl +++ b/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl @@ -7,6 +7,9 @@ include "File" importJava "org.simantics.spreadsheet.common.TableCell" where data TableCell +importJava "org.simantics.spreadsheet.common.TreeTableCell" where + data TreeTableCell + importJava "org.simantics.spreadsheet.common.SpreadsheetCell" where data SpreadsheetCell diff --git a/features/org.simantics.desktop.feature/.project b/features/org.simantics.desktop.feature/.project new file mode 100644 index 000000000..89848f6ca --- /dev/null +++ b/features/org.simantics.desktop.feature/.project @@ -0,0 +1,17 @@ + + + org.simantics.desktop.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/features/org.simantics.desktop.feature/build.properties b/features/org.simantics.desktop.feature/build.properties new file mode 100644 index 000000000..82ab19c62 --- /dev/null +++ b/features/org.simantics.desktop.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/features/org.simantics.desktop.feature/feature.xml b/features/org.simantics.desktop.feature/feature.xml new file mode 100644 index 000000000..d29ccac34 --- /dev/null +++ b/features/org.simantics.desktop.feature/feature.xml @@ -0,0 +1,70 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/features/org.simantics.desktop.product.feature/.project b/features/org.simantics.desktop.product.feature/.project new file mode 100644 index 000000000..293134267 --- /dev/null +++ b/features/org.simantics.desktop.product.feature/.project @@ -0,0 +1,17 @@ + + + org.simantics.desktop.product.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/features/org.simantics.desktop.product.feature/build.properties b/features/org.simantics.desktop.product.feature/build.properties new file mode 100644 index 000000000..82ab19c62 --- /dev/null +++ b/features/org.simantics.desktop.product.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/features/org.simantics.desktop.product.feature/feature.xml b/features/org.simantics.desktop.product.feature/feature.xml new file mode 100644 index 000000000..a7292c7ba --- /dev/null +++ b/features/org.simantics.desktop.product.feature/feature.xml @@ -0,0 +1,31 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + +