diff --git a/org.fortiss.tooling.common.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.common.ui/trunk/META-INF/MANIFEST.MF index e00e3e0bff737b21c8c41d77c3f365fc7c448efd..020da584b810939d5ebd19690e48ca403a4edb42 100644 --- a/org.fortiss.tooling.common.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.common.ui/trunk/META-INF/MANIFEST.MF @@ -16,7 +16,9 @@ Require-Bundle: org.fortiss.tooling.common;bundle-version="2.12.0";visibility:=r org.eclipse.gef;bundle-version="3.7.1";visibility:=reexport, org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.200";visibility:=reexport, org.eclipse.ui.ide;bundle-version="3.7.0";visibility:=reexport, - org.eclipse.jface.text;bundle-version="3.7.1";visibility:=reexport + org.eclipse.jface.text;bundle-version="3.7.1";visibility:=reexport, + org.eclipse.fx.ui.workbench3;bundle-version="0.9.0";visibility:=reexport, + org.eclipse.fx.javafx;bundle-version="2.2.0";resolution:=optional;visibility:=reexport Bundle-ClassPath: ., lib/org.conqat.ide.commons.gef.jar, lib/org.conqat.ide.commons.ui.jar, @@ -70,6 +72,7 @@ Export-Package: org.conqat.ide.commons.gef, org.eclipse.wb.swt, org.eclipse.wb.swt.layout.grouplayout, org.eclipse.wb.swt.widgets.baseline, + org.fortiss.tooling.common.ui.javafx, org.jgrapht, org.jgrapht.alg, org.jgrapht.alg.util, @@ -88,3 +91,5 @@ Export-Package: org.conqat.ide.commons.gef, org.jgrapht.traverse, org.jgrapht.util Bundle-Vendor: fortiss GmbH +Bundle-Activator: org.fortiss.tooling.common.ui.ToolingCommonUIActivator +Bundle-ActivationPolicy: lazy diff --git a/org.fortiss.tooling.common.ui/trunk/build.properties b/org.fortiss.tooling.common.ui/trunk/build.properties index cd7a139199e0563abe5130d672bac57672f6bb11..764af4d9356788b45c0daa99bb97676856b42da6 100644 --- a/org.fortiss.tooling.common.ui/trunk/build.properties +++ b/org.fortiss.tooling.common.ui/trunk/build.properties @@ -2,6 +2,7 @@ bin.includes = .,\ META-INF/,\ + res/,\ lib/org.conqat.ide.commons.gef.jar,\ lib/org.conqat.ide.commons.ui.jar,\ lib/jgrapht-jdk1.6_src.jar,\ diff --git a/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/.ratings b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..20b1e4469030f9571b68bd4f4cf77e6b99845e12 --- /dev/null +++ b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/.ratings @@ -0,0 +1 @@ +ToolingCommonUIActivator.java c93af6cea4d1baae5a0ed48fa055a0f2f88794dd YELLOW diff --git a/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/ToolingCommonUIActivator.java b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/ToolingCommonUIActivator.java new file mode 100644 index 0000000000000000000000000000000000000000..cce1178fb9941ee2d4d97cfdbe6af8cf94170fd3 --- /dev/null +++ b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/ToolingCommonUIActivator.java @@ -0,0 +1,58 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2011 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.common.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + * + * @author creator + */ +public class ToolingCommonUIActivator extends AbstractUIPlugin { + + /** The plug-in ID. */ + public static final String PLUGIN_ID = ToolingCommonUIActivator.class.getPackage().getName(); // $NON-NLS-1$ + + /** The shared instance. */ + private static ToolingCommonUIActivator plugin; + + /** {@inheritDoc} */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /** {@inheritDoc} */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** Returns the shared instance. */ + public static ToolingCommonUIActivator getDefault() { + return plugin; + } + + /** Returns the image descriptor for the given icon file. */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/javafx/.ratings b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/javafx/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..1db85a85da8a6441115b0b6bf92e5443f0253b7b --- /dev/null +++ b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/javafx/.ratings @@ -0,0 +1 @@ +AF3FXViewPart.java 8e1c1312fb7b21fb0b72a4b0978224b740a5e557 YELLOW diff --git a/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/javafx/AF3FXViewPart.java b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/javafx/AF3FXViewPart.java new file mode 100644 index 0000000000000000000000000000000000000000..0080c61a6b59fdf46f8ebe860a54c06ea6f87144 --- /dev/null +++ b/org.fortiss.tooling.common.ui/trunk/src/org/fortiss/tooling/common/ui/javafx/AF3FXViewPart.java @@ -0,0 +1,134 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2017 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.common.ui.javafx; + +import java.io.IOException; + +import javafx.application.Platform; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.BorderPane; + +import org.eclipse.fx.ui.workbench3.FXViewPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + +/** + * Base class to create eclipse (SWT-based) views using JavaFX GUI elements. This class requires + * FXML file that defines the GUI elements of the view. + * + * @author diewald + */ +public abstract class AF3FXViewPart extends FXViewPart { + /** Holds the relative path to the CSS file defining the Applications appearance. */ + private final static String CSSLOCATION = "/application.css"; + + /** For later use, if we need to define different styles. */ + private final String cssLocation; + + /** + * Holds the relative location of the FXML JavaXML files. Roots are the source folders of the + * (plugin) project. + */ + private final String fXMLLocation; + + /** References the stub that defines the FXML file defining the layout and controller. */ + private Class<? extends AF3FXViewPart> viewerClass; + + /** + * Constructor. Allows to pass the view's FXML definition file along with style. + * + * @param viewerClass + * Stub class that defines the FXML file defining the layout and controller + * @param fXMLLocation + * location of the fXML file relative to the source (resource) folders. + * @param cssLocation + * style sheet file path for the appearance settings relative to the source + * (resource) folders. + * @throws Exception + * if the given FXML file path is not given or if it cannot be found in any of the + * source (resource) folders. + */ + private AF3FXViewPart(Class<? extends AF3FXViewPart> viewerClass, String fXMLLocation, + String cssLocation) throws Exception { + if(fXMLLocation == null) { + throw new Exception( + "The location of the FXML file defining the gui elements was not given," + + "or it cannot be found at the given location (" + fXMLLocation + ") " + + "The view will NOT be created."); + } + + Platform.setImplicitExit(false); + this.viewerClass = viewerClass; + this.fXMLLocation = fXMLLocation; + this.cssLocation = cssLocation; + } + + /** + * Constructor. Allows to pass the view's FXML definition file. + * + * @param viewerClass + * Stub class that defines the FXML file defining the layout and controller + * @param fXMLLocation + * location of the fXML file relative to the source (resource) folders. + * @throws Exception + * if the given FXML file path is not given or if it cannot be found in any of the + * source (resource) folders. + */ + public AF3FXViewPart(Class<? extends AF3FXViewPart> viewerClass, String fXMLLocation) + throws Exception { + this(viewerClass, fXMLLocation, CSSLOCATION); + } + + /** {@inheritDoc} */ + @Override + public void createPartControl(Composite parent) { + if("gtk".equals(System.getProperty("osgi.ws"))) { + if(!"0".equals(System.getenv("SWT_GTK3"))) { + org.eclipse.swt.widgets.Label errorLabel = + new org.eclipse.swt.widgets.Label(parent, SWT.BOLD); + errorLabel + .setText("Cannot show JavaFX view without setting SWT_GTK3 to '0'.\n" + + "Please relaunch Eclipse using a terminal and 'SWT_GTK3=0 ./eclipse' command."); + return; + } + } + super.createPartControl(parent); + } + + /** {@inheritDoc} */ + @Override + protected Scene createFxScene() { + BorderPane root = null; + FXMLLoader loader = new FXMLLoader(); + loader.setClassLoader(viewerClass.getClassLoader()); + loader.setLocation(viewerClass.getResource(fXMLLocation)); + try { + root = (BorderPane)loader.load(); + } catch(IOException e) { + throw new RuntimeException("Cannot load the resource located at " + fXMLLocation, e); + } + Scene scene = new Scene(root, 400, 400); + scene.getStylesheets().add(getClass().getResource(cssLocation).toExternalForm()); + return scene; + } + + /** {@inheritDoc} */ + @Override + protected void setFxFocus() { + // Not needed. + } +}