diff --git "a/uaalfilecreator/fc_test - Verkn\303\274pfung.lnk" "b/uaalfilecreator/fc_test - Verkn\303\274pfung.lnk" new file mode 100644 index 0000000000000000000000000000000000000000..b4f86f0da27343b77a23602410ca5a3e973a5a75 Binary files /dev/null and "b/uaalfilecreator/fc_test - Verkn\303\274pfung.lnk" differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/.classpath b/uaalfilecreator/org.universaal.tools.uaalcreator/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..27da85061161cd8c994de6d5a6fce7ed257f446d --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="icons"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/.project b/uaalfilecreator/org.universaal.tools.uaalcreator/.project new file mode 100644 index 0000000000000000000000000000000000000000..2031bb6a91528d4888f4785eb85bd3cbdd3db404 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.universaal.tools.uaalcreator</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/.settings/org.eclipse.jdt.core.prefs b/uaalfilecreator/org.universaal.tools.uaalcreator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..dbcb91b01a06f6b74a1e0fabb4ab117ba8d405be --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Fri Sep 23 01:46:41 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/META-INF/MANIFEST.MF b/uaalfilecreator/org.universaal.tools.uaalcreator/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..c431f80d2b430d84f2eb3f8dd0fa27869c453ab6 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.universaal.tools.uaalcreator;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.universaal.tools.uaalcreator.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.resources;bundle-version="3.7.100" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ClassPath: . +Export-Package: ., + org.universaal.tools.uaalcreator diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/OSGI-INF/l10n/bundle.properties b/uaalfilecreator/org.universaal.tools.uaalcreator/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..03b43e18a59d425a50b7e807f764b5731693dc4a --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for CE +Bundle-Name = ConfigurationExtractor \ No newline at end of file diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/FileWithComments.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/FileWithComments.class new file mode 100644 index 0000000000000000000000000000000000000000..55812c91ae2ee073ecca320034fd754d00e28483 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/FileWithComments.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/document-save-as.png b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/document-save-as.png new file mode 100644 index 0000000000000000000000000000000000000000..bd1705c1ce49f2f0ddeb02a13f5567e02bbc3bc7 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/document-save-as.png differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager$1.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager$1.class new file mode 100644 index 0000000000000000000000000000000000000000..43a64c7aa6a2b20f266b5412c4421107545977eb Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager$1.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager$PluginResourceProvider.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager$PluginResourceProvider.class new file mode 100644 index 0000000000000000000000000000000000000000..1559553b6650ba4b38d5243c5750dc2063d07296 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager$PluginResourceProvider.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager.class new file mode 100644 index 0000000000000000000000000000000000000000..f7a163c3c65cbca615a0b260ad2cea17b18a521a Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/ResourceManager.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/SWTResourceManager.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/SWTResourceManager.class new file mode 100644 index 0000000000000000000000000000000000000000..ec555497904577478e0b8271dcc8f570e358a887 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/eclipse/wb/swt/SWTResourceManager.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/Activator.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/Activator.class new file mode 100644 index 0000000000000000000000000000000000000000..eacb6a4131ab538bc72085c12c4879728d600ee9 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/Activator.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/actions/UaalCreatorAction.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/actions/UaalCreatorAction.class new file mode 100644 index 0000000000000000000000000000000000000000..32a5cad83e889616310b6e1e3f15f5239c19c4a3 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/actions/UaalCreatorAction.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/ConfigItem.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/ConfigItem.class new file mode 100644 index 0000000000000000000000000000000000000000..21e659ca2dd492078601043f1488549728f94daf Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/ConfigItem.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/GeneralUCConfig.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/GeneralUCConfig.class new file mode 100644 index 0000000000000000000000000000000000000000..b856ac4f6405ae2e5f212a1bb5c09dd665d5463c Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/GeneralUCConfig.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/ItemType.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/ItemType.class new file mode 100644 index 0000000000000000000000000000000000000000..3502b1570b20da889a90c87bbbfc90855115f6f0 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/data/ItemType.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/handlers/UaalCreatorHandler.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/handlers/UaalCreatorHandler.class new file mode 100644 index 0000000000000000000000000000000000000000..4aedf35ddf63bc9002e1b43e1c0df3492edd0ada Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/handlers/UaalCreatorHandler.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView$1.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView$1.class new file mode 100644 index 0000000000000000000000000000000000000000..5993f0e4ea5f84efe8e7e8d92293a701449ef029 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView$1.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView$2.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView$2.class new file mode 100644 index 0000000000000000000000000000000000000000..50771f05e38e28a2375ba55d40de2c90a1d33e79 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView$2.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView.class b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView.class new file mode 100644 index 0000000000000000000000000000000000000000..f7264b853e8df49ff2d03f8b9e54172063ff8f3d Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/bin/org/universaal/tools/uaalcreator/view/UaalCreatorView.class differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/build.properties b/uaalfilecreator/org.universaal.tools.uaalcreator/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..3088888bf411696599f053e3f20728327fc529fe --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/build.properties @@ -0,0 +1,9 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + icons/,\ + src/ +jars.compile.order = . + diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/icons/document-save-as.png b/uaalfilecreator/org.universaal.tools.uaalcreator/icons/document-save-as.png new file mode 100644 index 0000000000000000000000000000000000000000..bd1705c1ce49f2f0ddeb02a13f5567e02bbc3bc7 Binary files /dev/null and b/uaalfilecreator/org.universaal.tools.uaalcreator/icons/document-save-as.png differ diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/plugin.xml b/uaalfilecreator/org.universaal.tools.uaalcreator/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..7e064bbe0c08714d390178a7bf7039281566e311 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/plugin.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + + <!-- View --> + + <extension + point="org.eclipse.ui.views"> + <category + name="AAL Studio" + id="org.universaal.tools.uaalcreator"> + </category> + <view + category="org.universaal.tools.uaalcreator" + class="org.universaal.tools.uaalcreator.view.UaalCreatorView" + id="org.universaal.tools.uaalcreator.UaalCreatorView" + name="*.uaal file creator"> + </view> + </extension> + + <!-- --> + + <extension + point="org.eclipse.ui.actionSets"> + <actionSet + label="Sample Action Set" + visible="true" + id="org.universaal.tools.uaalcreator.actionSet"> + <action + label="&Create the *.uaal file" + icon="icons/document-save-as.png" + class="org.universaal.tools.uaalcreator.actions.UaalCreatorAction" + tooltip="Create the *.uaal file" + menubarPath="org.universaal.tools.AALStudio.menu/build" + toolbarPath="uAALGroup" + id="org.universaal.tools.uaalcreator.UaalCreatorAction"> + </action> + </actionSet> + </extension> + + + <extension + point="org.eclipse.ui.commands"> + <category + name="universAAL" + id="org.universaal.tools.uaalcreator.commands"> + </category> + <command + name="Build application" + categoryId="org.universaal.tools.uaalcreator.commands" + id="org.universaal.tools.uaalcreator.actions.UaalCreatorAction"> + </command> + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + commandId="org.universaal.tools.uaalcreator.UaalCreatorAction" + class="org.universaal.tools.uaalcreator.handlers.UaalCreatorHandler"> + </handler> + </extension> + + +</plugin> diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/FileWithComments.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/FileWithComments.java new file mode 100644 index 0000000000000000000000000000000000000000..1af8563d3874577e94647961ac5f76fdbd4b47e4 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/FileWithComments.java @@ -0,0 +1,36 @@ + + + +public class FileWithComments { + + //Configuration Extractor: Define the usecase configuration + //$$ucconfig $ucname "My usecase" $versionnr "1.1" $author "Alexander Schwende" + //$$uid d14bc3af-e62f-455a-90da-18f2be9fd5b4 + + + //Configuration Extractor: Define a new panel + //the following variables will be located in this panel + //$$panel $caption "Warning configuration" + + + //Configuration Extractor: Define a new variable + //$$variable $name header $type int $label "LABEL_TEXT" $hover "HOVER_TEXT" +// private TYPE NAME; + //Configuration Extractor: Define a new variable + //$$variable $name message $type int $label "LABEL_TEXT" $hover "HOVER_TEXT" +// private TYPE NAME; + //Configuration Extractor: Define a new variable + //$$variable $name footer $type int $label "LABEL_TEXT" $hover "HOVER_TEXT" +// private TYPE NAME; + + + //Configuration Extractor: Define an Ontology Panel + //$$ontologypanel $caption "caregiver configuration" $name caregiver $domain DOMAIN $label "Caregiver:" $hover "Please select the caregiver here" +// private DOMAIN NAME; + + //Configuration Extractor: Define a new variable + //$$variable $name hasPhoneNumber $type String $label "phone number" $hover "huhu" + private int inttest; + + +} diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/eclipse/wb/swt/ResourceManager.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/eclipse/wb/swt/ResourceManager.java new file mode 100644 index 0000000000000000000000000000000000000000..4bfbc6b6ef9229038dc3dd1d222caa8575f0ff04 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/eclipse/wb/swt/ResourceManager.java @@ -0,0 +1,415 @@ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc. + * 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: + * Google, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.wb.swt; + +import java.io.File; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.osgi.framework.Bundle; + +/** + * Utility class for managing OS resources associated with SWT/JFace controls such as colors, fonts, images, + * etc. + * + * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the + * operating system resources managed by cached objects when those objects and OS resources are no longer + * needed (e.g. on application shutdown) + * + * This class may be freely distributed as part of any application or plugin. + * <p> + * + * @author scheglov_ke + * @author Dan Rubel + */ +public class ResourceManager extends SWTResourceManager { + //////////////////////////////////////////////////////////////////////////// + // + // Image + // + //////////////////////////////////////////////////////////////////////////// + private static Map<ImageDescriptor, Image> m_descriptorImageMap = new HashMap<ImageDescriptor, Image>(); + /** + * Returns an {@link ImageDescriptor} stored in the file at the specified path relative to the specified + * class. + * + * @param clazz + * the {@link Class} relative to which to find the image descriptor. + * @param path + * the path to the image file. + * @return the {@link ImageDescriptor} stored in the file at the specified path. + */ + public static ImageDescriptor getImageDescriptor(Class<?> clazz, String path) { + return ImageDescriptor.createFromFile(clazz, path); + } + /** + * Returns an {@link ImageDescriptor} stored in the file at the specified path. + * + * @param path + * the path to the image file. + * @return the {@link ImageDescriptor} stored in the file at the specified path. + */ + public static ImageDescriptor getImageDescriptor(String path) { + try { + return ImageDescriptor.createFromURL(new File(path).toURI().toURL()); + } catch (MalformedURLException e) { + return null; + } + } + /** + * Returns an {@link Image} based on the specified {@link ImageDescriptor}. + * + * @param descriptor + * the {@link ImageDescriptor} for the {@link Image}. + * @return the {@link Image} based on the specified {@link ImageDescriptor}. + */ + public static Image getImage(ImageDescriptor descriptor) { + if (descriptor == null) { + return null; + } + Image image = m_descriptorImageMap.get(descriptor); + if (image == null) { + image = descriptor.createImage(); + m_descriptorImageMap.put(descriptor, image); + } + return image; + } + /** + * Maps images to decorated images. + */ + @SuppressWarnings("unchecked") + private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated. + * @param decorator + * the {@link Image} to decorate the base image. + * @return {@link Image} The resulting decorated image. + */ + public static Image decorateImage(Image baseImage, Image decorator) { + return decorateImage(baseImage, decorator, BOTTOM_RIGHT); + } + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated. + * @param decorator + * the {@link Image} to decorate the base image. + * @param corner + * the corner to place decorator image. + * @return the resulting decorated {@link Image}. + */ + public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { + if (corner <= 0 || corner >= LAST_CORNER_KEY) { + throw new IllegalArgumentException("Wrong decorate corner"); + } + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; + if (cornerDecoratedImageMap == null) { + cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); + m_decoratedImageMap[corner] = cornerDecoratedImageMap; + } + Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); + if (decoratedMap == null) { + decoratedMap = new HashMap<Image, Image>(); + cornerDecoratedImageMap.put(baseImage, decoratedMap); + } + // + Image result = decoratedMap.get(decorator); + if (result == null) { + final Rectangle bib = baseImage.getBounds(); + final Rectangle dib = decorator.getBounds(); + final Point baseImageSize = new Point(bib.width, bib.height); + CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() { + @Override + protected void drawCompositeImage(int width, int height) { + drawImage(baseImage.getImageData(), 0, 0); + if (corner == TOP_LEFT) { + drawImage(decorator.getImageData(), 0, 0); + } else if (corner == TOP_RIGHT) { + drawImage(decorator.getImageData(), bib.width - dib.width, 0); + } else if (corner == BOTTOM_LEFT) { + drawImage(decorator.getImageData(), 0, bib.height - dib.height); + } else if (corner == BOTTOM_RIGHT) { + drawImage(decorator.getImageData(), bib.width - dib.width, bib.height - dib.height); + } + } + @Override + protected Point getSize() { + return baseImageSize; + } + }; + // + result = compositImageDesc.createImage(); + decoratedMap.put(decorator, result); + } + return result; + } + /** + * Dispose all of the cached images. + */ + public static void disposeImages() { + SWTResourceManager.disposeImages(); + // dispose ImageDescriptor images + { + for (Iterator<Image> I = m_descriptorImageMap.values().iterator(); I.hasNext();) { + I.next().dispose(); + } + m_descriptorImageMap.clear(); + } + // dispose decorated images + for (int i = 0; i < m_decoratedImageMap.length; i++) { + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; + if (cornerDecoratedImageMap != null) { + for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { + for (Image image : decoratedMap.values()) { + image.dispose(); + } + decoratedMap.clear(); + } + cornerDecoratedImageMap.clear(); + } + } + // dispose plugin images + { + for (Iterator<Image> I = m_URLImageMap.values().iterator(); I.hasNext();) { + I.next().dispose(); + } + m_URLImageMap.clear(); + } + } + //////////////////////////////////////////////////////////////////////////// + // + // Plugin images support + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps URL to images. + */ + private static Map<String, Image> m_URLImageMap = new HashMap<String, Image>(); + /** + * Provider for plugin resources, used by WindowBuilder at design time. + */ + public interface PluginResourceProvider { + URL getEntry(String symbolicName, String path); + } + /** + * Instance of {@link PluginResourceProvider}, used by WindowBuilder at design time. + */ + private static PluginResourceProvider m_designTimePluginResourceProvider = null; + /** + * Returns an {@link Image} based on a plugin and file path. + * + * @param plugin + * the plugin {@link Object} containing the image + * @param name + * the path to the image within the plugin + * @return the {@link Image} stored in the file at the specified path + * + * @deprecated Use {@link #getPluginImage(String, String)} instead. + */ + @Deprecated + public static Image getPluginImage(Object plugin, String name) { + try { + URL url = getPluginImageURL(plugin, name); + if (url != null) { + return getPluginImageFromUrl(url); + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + /** + * Returns an {@link Image} based on a {@link Bundle} and resource entry path. + * + * @param symbolicName + * the symbolic name of the {@link Bundle}. + * @param path + * the path of the resource entry. + * @return the {@link Image} stored in the file at the specified path. + */ + public static Image getPluginImage(String symbolicName, String path) { + try { + URL url = getPluginImageURL(symbolicName, path); + if (url != null) { + return getPluginImageFromUrl(url); + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + /** + * Returns an {@link Image} based on given {@link URL}. + */ + private static Image getPluginImageFromUrl(URL url) { + try { + try { + String key = url.toExternalForm(); + Image image = m_URLImageMap.get(key); + if (image == null) { + InputStream stream = url.openStream(); + try { + image = getImage(stream); + m_URLImageMap.put(key, image); + } finally { + stream.close(); + } + } + return image; + } catch (Throwable e) { + // Ignore any exceptions + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + /** + * Returns an {@link ImageDescriptor} based on a plugin and file path. + * + * @param plugin + * the plugin {@link Object} containing the image. + * @param name + * the path to th eimage within the plugin. + * @return the {@link ImageDescriptor} stored in the file at the specified path. + * + * @deprecated Use {@link #getPluginImageDescriptor(String, String)} instead. + */ + @Deprecated + public static ImageDescriptor getPluginImageDescriptor(Object plugin, String name) { + try { + try { + URL url = getPluginImageURL(plugin, name); + return ImageDescriptor.createFromURL(url); + } catch (Throwable e) { + // Ignore any exceptions + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + /** + * Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource entry path. + * + * @param symbolicName + * the symbolic name of the {@link Bundle}. + * @param path + * the path of the resource entry. + * @return the {@link ImageDescriptor} based on a {@link Bundle} and resource entry path. + */ + public static ImageDescriptor getPluginImageDescriptor(String symbolicName, String path) { + try { + URL url = getPluginImageURL(symbolicName, path); + if (url != null) { + return ImageDescriptor.createFromURL(url); + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + /** + * Returns an {@link URL} based on a {@link Bundle} and resource entry path. + */ + private static URL getPluginImageURL(String symbolicName, String path) { + // try runtime plugins + { + Bundle bundle = Platform.getBundle(symbolicName); + if (bundle != null) { + return bundle.getEntry(path); + } + } + // try design time provider + if (m_designTimePluginResourceProvider != null) { + return m_designTimePluginResourceProvider.getEntry(symbolicName, path); + } + // no such resource + return null; + } + /** + * Returns an {@link URL} based on a plugin and file path. + * + * @param plugin + * the plugin {@link Object} containing the file path. + * @param name + * the file path. + * @return the {@link URL} representing the file at the specified path. + * @throws Exception + */ + private static URL getPluginImageURL(Object plugin, String name) throws Exception { + // try to work with 'plugin' as with OSGI BundleContext + try { + Class<?> BundleClass = Class.forName("org.osgi.framework.Bundle"); //$NON-NLS-1$ + Class<?> BundleContextClass = Class.forName("org.osgi.framework.BundleContext"); //$NON-NLS-1$ + if (BundleContextClass.isAssignableFrom(plugin.getClass())) { + Method getBundleMethod = BundleContextClass.getMethod("getBundle", new Class[0]); //$NON-NLS-1$ + Object bundle = getBundleMethod.invoke(plugin, new Object[0]); + // + Class<?> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ + Constructor<?> pathConstructor = PathClass.getConstructor(new Class[]{String.class}); + Object path = pathConstructor.newInstance(new Object[]{name}); + // + Class<?> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ + Class<?> PlatformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$ + Method findMethod = PlatformClass.getMethod("find", new Class[]{BundleClass, IPathClass}); //$NON-NLS-1$ + return (URL) findMethod.invoke(null, new Object[]{bundle, path}); + } + } catch (Throwable e) { + // Ignore any exceptions + } + // else work with 'plugin' as with usual Eclipse plugin + { + Class<?> PluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); //$NON-NLS-1$ + if (PluginClass.isAssignableFrom(plugin.getClass())) { + // + Class<?> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ + Constructor<?> pathConstructor = PathClass.getConstructor(new Class[]{String.class}); + Object path = pathConstructor.newInstance(new Object[]{name}); + // + Class<?> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ + Method findMethod = PluginClass.getMethod("find", new Class[]{IPathClass}); //$NON-NLS-1$ + return (URL) findMethod.invoke(plugin, new Object[]{path}); + } + } + return null; + } + //////////////////////////////////////////////////////////////////////////// + // + // General + // + //////////////////////////////////////////////////////////////////////////// + /** + * Dispose of cached objects and their underlying OS resources. This should only be called when the cached + * objects are no longer needed (e.g. on application shutdown). + */ + public static void dispose() { + disposeColors(); + disposeFonts(); + disposeImages(); + } +} \ No newline at end of file diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/eclipse/wb/swt/SWTResourceManager.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/eclipse/wb/swt/SWTResourceManager.java new file mode 100644 index 0000000000000000000000000000000000000000..8b6d4cc3ffec8aceabd59822e031990300d2e59a --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/eclipse/wb/swt/SWTResourceManager.java @@ -0,0 +1,447 @@ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc. + * 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: + * Google, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.wb.swt; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Display; + +/** + * Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc. + * <p> + * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the + * operating system resources managed by cached objects when those objects and OS resources are no longer + * needed (e.g. on application shutdown) + * <p> + * This class may be freely distributed as part of any application or plugin. + * <p> + * @author scheglov_ke + * @author Dan Rubel + */ +public class SWTResourceManager { + //////////////////////////////////////////////////////////////////////////// + // + // Color + // + //////////////////////////////////////////////////////////////////////////// + private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>(); + /** + * Returns the system {@link Color} matching the specific ID. + * + * @param systemColorID + * the ID value for the color + * @return the system {@link Color} matching the specific ID + */ + public static Color getColor(int systemColorID) { + Display display = Display.getCurrent(); + return display.getSystemColor(systemColorID); + } + /** + * Returns a {@link Color} given its red, green and blue component values. + * + * @param r + * the red component of the color + * @param g + * the green component of the color + * @param b + * the blue component of the color + * @return the {@link Color} matching the given red, green and blue component values + */ + public static Color getColor(int r, int g, int b) { + return getColor(new RGB(r, g, b)); + } + /** + * Returns a {@link Color} given its RGB value. + * + * @param rgb + * the {@link RGB} value of the color + * @return the {@link Color} matching the RGB value + */ + public static Color getColor(RGB rgb) { + Color color = m_colorMap.get(rgb); + if (color == null) { + Display display = Display.getCurrent(); + color = new Color(display, rgb); + m_colorMap.put(rgb, color); + } + return color; + } + /** + * Dispose of all the cached {@link Color}'s. + */ + public static void disposeColors() { + for (Color color : m_colorMap.values()) { + color.dispose(); + } + m_colorMap.clear(); + } + //////////////////////////////////////////////////////////////////////////// + // + // Image + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps image paths to images. + */ + private static Map<String, Image> m_imageMap = new HashMap<String, Image>(); + /** + * Returns an {@link Image} encoded by the specified {@link InputStream}. + * + * @param stream + * the {@link InputStream} encoding the image data + * @return the {@link Image} encoded by the specified input stream + */ + protected static Image getImage(InputStream stream) throws IOException { + try { + Display display = Display.getCurrent(); + ImageData data = new ImageData(stream); + if (data.transparentPixel > 0) { + return new Image(display, data, data.getTransparencyMask()); + } + return new Image(display, data); + } finally { + stream.close(); + } + } + /** + * Returns an {@link Image} stored in the file at the specified path. + * + * @param path + * the path to the image file + * @return the {@link Image} stored in the file at the specified path + */ + public static Image getImage(String path) { + Image image = m_imageMap.get(path); + if (image == null) { + try { + image = getImage(new FileInputStream(path)); + m_imageMap.put(path, image); + } catch (Exception e) { + image = getMissingImage(); + m_imageMap.put(path, image); + } + } + return image; + } + /** + * Returns an {@link Image} stored in the file at the specified path relative to the specified class. + * + * @param clazz + * the {@link Class} relative to which to find the image + * @param path + * the path to the image file, if starts with <code>'/'</code> + * @return the {@link Image} stored in the file at the specified path + */ + public static Image getImage(Class<?> clazz, String path) { + String key = clazz.getName() + '|' + path; + Image image = m_imageMap.get(key); + if (image == null) { + try { + image = getImage(clazz.getResourceAsStream(path)); + m_imageMap.put(key, image); + } catch (Exception e) { + image = getMissingImage(); + m_imageMap.put(key, image); + } + } + return image; + } + private static final int MISSING_IMAGE_SIZE = 10; + /** + * @return the small {@link Image} that can be used as placeholder for missing image. + */ + private static Image getMissingImage() { + Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); + // + GC gc = new GC(image); + gc.setBackground(getColor(SWT.COLOR_RED)); + gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); + gc.dispose(); + // + return image; + } + /** + * Style constant for placing decorator image in top left corner of base image. + */ + public static final int TOP_LEFT = 1; + /** + * Style constant for placing decorator image in top right corner of base image. + */ + public static final int TOP_RIGHT = 2; + /** + * Style constant for placing decorator image in bottom left corner of base image. + */ + public static final int BOTTOM_LEFT = 3; + /** + * Style constant for placing decorator image in bottom right corner of base image. + */ + public static final int BOTTOM_RIGHT = 4; + /** + * Internal value. + */ + protected static final int LAST_CORNER_KEY = 5; + /** + * Maps images to decorated images. + */ + @SuppressWarnings("unchecked") + private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated + * @param decorator + * the {@link Image} to decorate the base image + * @return {@link Image} The resulting decorated image + */ + public static Image decorateImage(Image baseImage, Image decorator) { + return decorateImage(baseImage, decorator, BOTTOM_RIGHT); + } + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated + * @param decorator + * the {@link Image} to decorate the base image + * @param corner + * the corner to place decorator image + * @return the resulting decorated {@link Image} + */ + public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { + if (corner <= 0 || corner >= LAST_CORNER_KEY) { + throw new IllegalArgumentException("Wrong decorate corner"); + } + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; + if (cornerDecoratedImageMap == null) { + cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); + m_decoratedImageMap[corner] = cornerDecoratedImageMap; + } + Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); + if (decoratedMap == null) { + decoratedMap = new HashMap<Image, Image>(); + cornerDecoratedImageMap.put(baseImage, decoratedMap); + } + // + Image result = decoratedMap.get(decorator); + if (result == null) { + Rectangle bib = baseImage.getBounds(); + Rectangle dib = decorator.getBounds(); + // + result = new Image(Display.getCurrent(), bib.width, bib.height); + // + GC gc = new GC(result); + gc.drawImage(baseImage, 0, 0); + if (corner == TOP_LEFT) { + gc.drawImage(decorator, 0, 0); + } else if (corner == TOP_RIGHT) { + gc.drawImage(decorator, bib.width - dib.width, 0); + } else if (corner == BOTTOM_LEFT) { + gc.drawImage(decorator, 0, bib.height - dib.height); + } else if (corner == BOTTOM_RIGHT) { + gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); + } + gc.dispose(); + // + decoratedMap.put(decorator, result); + } + return result; + } + /** + * Dispose all of the cached {@link Image}'s. + */ + public static void disposeImages() { + // dispose loaded images + { + for (Image image : m_imageMap.values()) { + image.dispose(); + } + m_imageMap.clear(); + } + // dispose decorated images + for (int i = 0; i < m_decoratedImageMap.length; i++) { + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; + if (cornerDecoratedImageMap != null) { + for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { + for (Image image : decoratedMap.values()) { + image.dispose(); + } + decoratedMap.clear(); + } + cornerDecoratedImageMap.clear(); + } + } + } + //////////////////////////////////////////////////////////////////////////// + // + // Font + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps font names to fonts. + */ + private static Map<String, Font> m_fontMap = new HashMap<String, Font>(); + /** + * Maps fonts to their bold versions. + */ + private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>(); + /** + * Returns a {@link Font} based on its name, height and style. + * + * @param name + * the name of the font + * @param height + * the height of the font + * @param style + * the style of the font + * @return {@link Font} The font matching the name, height and style + */ + public static Font getFont(String name, int height, int style) { + return getFont(name, height, style, false, false); + } + /** + * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline + * flags are also supported. + * + * @param name + * the name of the font + * @param size + * the size of the font + * @param style + * the style of the font + * @param strikeout + * the strikeout flag (warning: Windows only) + * @param underline + * the underline flag (warning: Windows only) + * @return {@link Font} The font matching the name, height, style, strikeout and underline + */ + public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { + String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; + Font font = m_fontMap.get(fontName); + if (font == null) { + FontData fontData = new FontData(name, size, style); + if (strikeout || underline) { + try { + Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$ + Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$ + if (logFont != null && logFontClass != null) { + if (strikeout) { + logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ + } + if (underline) { + logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ + } + } + } catch (Throwable e) { + System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + font = new Font(Display.getCurrent(), fontData); + m_fontMap.put(fontName, font); + } + return font; + } + /** + * Returns a bold version of the given {@link Font}. + * + * @param baseFont + * the {@link Font} for which a bold version is desired + * @return the bold version of the given {@link Font} + */ + public static Font getBoldFont(Font baseFont) { + Font font = m_fontToBoldFontMap.get(baseFont); + if (font == null) { + FontData fontDatas[] = baseFont.getFontData(); + FontData data = fontDatas[0]; + font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD); + m_fontToBoldFontMap.put(baseFont, font); + } + return font; + } + /** + * Dispose all of the cached {@link Font}'s. + */ + public static void disposeFonts() { + // clear fonts + for (Font font : m_fontMap.values()) { + font.dispose(); + } + m_fontMap.clear(); + // clear bold fonts + for (Font font : m_fontToBoldFontMap.values()) { + font.dispose(); + } + m_fontToBoldFontMap.clear(); + } + //////////////////////////////////////////////////////////////////////////// + // + // Cursor + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps IDs to cursors. + */ + private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>(); + /** + * Returns the system cursor matching the specific ID. + * + * @param id + * int The ID value for the cursor + * @return Cursor The system cursor matching the specific ID + */ + public static Cursor getCursor(int id) { + Integer key = Integer.valueOf(id); + Cursor cursor = m_idToCursorMap.get(key); + if (cursor == null) { + cursor = new Cursor(Display.getDefault(), id); + m_idToCursorMap.put(key, cursor); + } + return cursor; + } + /** + * Dispose all of the cached cursors. + */ + public static void disposeCursors() { + for (Cursor cursor : m_idToCursorMap.values()) { + cursor.dispose(); + } + m_idToCursorMap.clear(); + } + //////////////////////////////////////////////////////////////////////////// + // + // General + // + //////////////////////////////////////////////////////////////////////////// + /** + * Dispose of cached objects and their underlying OS resources. This should only be called when the cached + * objects are no longer needed (e.g. on application shutdown). + */ + public static void dispose() { + disposeColors(); + disposeImages(); + disposeFonts(); + disposeCursors(); + } +} \ No newline at end of file diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/Activator.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..2f11c68ede4d18ebf3ac383ad837d5dc0821eed4 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/Activator.java @@ -0,0 +1,35 @@ +package org.universaal.tools.uaalcreator; + +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.universaal.tools.uaalcreator"; + + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + System.out.println("uAAL file creator started"); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + System.out.println("uAAL file creator stoped"); + } + + +} diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/actions/UaalCreatorAction.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/actions/UaalCreatorAction.java new file mode 100644 index 0000000000000000000000000000000000000000..7c9b00829fb72e61e69df62294cd1c3cabe04dbf --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/actions/UaalCreatorAction.java @@ -0,0 +1,39 @@ +package org.universaal.tools.uaalcreator.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.universaal.tools.uaalcreator.view.UaalCreatorView; + +/** + * Our sample action implements workbench action delegate. The action proxy will + * be created by the workbench and shown in the UI. When the user tries to use + * the action, this delegate will be created and execution will be delegated to + * it. + * + * @see IWorkbenchWindowActionDelegate + */ +public class UaalCreatorAction implements IWorkbenchWindowActionDelegate { + + public void init(IWorkbenchWindow window) { + } + + public void dispose() {} + + public void run(IAction action) { + try { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(UaalCreatorView.ID); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + + public void selectionChanged(IAction action, ISelection selection) { + + } + + +} \ No newline at end of file diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/ConfigItem.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/ConfigItem.java new file mode 100644 index 0000000000000000000000000000000000000000..ef0ed67f6e06eee0743047ea5fc9f76cc0ced937 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/ConfigItem.java @@ -0,0 +1,205 @@ +package org.universaal.tools.uaalcreator.data; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +/** + * ConfigItem contains data about a single config item, which can be a panel, variable or ontology panel. + * + * @author schwende + */ +public class ConfigItem { + + public static final String NAME = "name"; + public static final String LABEL = "label"; + public static final String HOVER = "hover"; + public static final String CAPTION = "caption"; + public static final String DOMAIN = "domain"; + public static final String TYPE = "type"; + + /** + * array containing the allowed variable types + */ + private static final String[] allowedTypesArray = new String[] {"String", "int", "boolean"}; + /** + * list containing the allowed variable types + */ + private static List<String> allowedTypes = Arrays.asList(allowedTypesArray); + + private ItemType itemType; + private String name, label, hover, caption, domain, type; + + /** + * constructor of a ConfigItem of type t + * @param t ItemType of this ConfigItem + */ + public ConfigItem(ItemType t) { + setItemType(t); + } + + /** + * constructor of a ConfigItem whose ItemType is not specified yet + */ + public ConfigItem() {}; + + + public ItemType getItemType() { + return itemType; + } + public void setItemType(ItemType itemType) { + this.itemType = itemType; + } + + public String getName() { + return name; + } + private void setName(String name) { + this.name = name; + } + + public String getLabel() { + return label; + } + private void setLabel(String label) { + this.label = label; + } + + public String getHover() { + return hover; + } + private void setHover(String hover) { + this.hover = hover; + } + + public String getCaption() { + return caption; + } + private void setCaption(String caption) { + this.caption = caption; + } + + public String getDomain() { + return domain; + } + private void setDomain(String domain) { + this.domain = domain; + } + + public String getType() { + return type; + } + private void setType(String type) { + this.type = type; + } + + + /** + * set a parameter in this ConfigItem + * @param param parameter to set + * @param value value to set the parameter to + * @return true if successful + */ + public boolean setParameter(String param, String value) { + if (param.equals(NAME)) { + setName(value); + } else if (param.equals(LABEL)) { + setLabel(value); + } else if (param.equals(HOVER)) { + setHover(value); + } else if (param.equals(CAPTION)) { + setCaption(value); + } else if (param.equals(DOMAIN)) { + setDomain(value); + } else if (param.equals(TYPE)) { + setType(value); + } else { + return false; + } + + return true; + } + + /** + * @param param parameter to get the value from + * @return value of the given parameter + */ + public String getParameter(String param) { + if (param.equals(NAME)) { + return getName(); + } else if (param.equals(LABEL)) { + return getLabel(); + } else if (param.equals(HOVER)) { + return getHover(); + } else if (param.equals(CAPTION)) { + return getCaption(); + } else if (param.equals(DOMAIN)) { + return getDomain(); + } else if (param.equals(TYPE)) { + return getType(); + } else { + return null; + } + } + + + /** + * validates the config item + * @return an error message when an error is found, or null if no error is found + */ + public String validate(Set<String> varNames) { + + switch (getItemType()) { + case VARIABLE: + // check if the name is set + if (getName() == null || getName().isEmpty()) { + return "The name for a variable is not set!"; + + // check if the name already exists + } else if (varNames.contains(getName())) { + return "The name '" + getName() + "' already exists!"; + + // check if the variable type exists + } else if (! allowedTypes.contains(getType())) { + return "The variable type is unknown: " + getType(); + } + varNames.add(getName()); + break; + case ONTOLOGY_PANEL: + // check if the name is set + if (getName() == null || getName().isEmpty()) { + return "The name for an ontology concept is not set!"; + + // check if the name already exists + } else if (varNames.contains(getName())) { + return "The name '" + getName() + "' already exists!"; + + } + varNames.add(getName()); + break; + } + + return null; + } + + /** + * @return a List containing the allowed types for a variable + */ + public static String[] getAllowedTypes() { + return allowedTypesArray; + } + + /** + * @return index of the variable type configured in this item + */ + public int getTypeIndex() { + for (int i = 0; i < allowedTypesArray.length; i++) { + if (allowedTypesArray[i].equals(type)) { + return i; + } + } + + return -1; + } + +} diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/GeneralUCConfig.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/GeneralUCConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..c9f053f0aa58ab3e678921c160602746bc5f25f9 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/GeneralUCConfig.java @@ -0,0 +1,116 @@ +package org.universaal.tools.uaalcreator.data; + +import java.util.Set; +import java.util.UUID; + +/** + * GeneralUCConfig contains general configuration data for the usecase + * + * @author schwende + */ +public class GeneralUCConfig extends ConfigItem { + + public static final String UC_NAME = "ucname"; + public static final String VERSION_NR = "versionnr"; + public static final String AUTHOR = "author"; + public static final String UID = "uid"; + + private String versionNr = "", ucName = "", author = "", uid = ""; + + public GeneralUCConfig() { + } + + public String getVersionNr() { + return versionNr; + } + + public void setVersionNr(String versionNr) { + this.versionNr = versionNr; + } + + public String getUcName() { + return ucName; + } + + public void setUcName(String ucName) { + this.ucName = ucName; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getUid() { + if (uid == null || uid.isEmpty()) { + uid = UUID.randomUUID().toString(); + } + return uid; + } + + @Override public boolean setParameter(String param, String value) { + if (super.setParameter(param, value)) { + return true; + } + + if (param.equals(UC_NAME)) { + setUcName(value); + } else if (param.equals(VERSION_NR)) { + setVersionNr(value); + } else if (param.equals(AUTHOR)) { + setAuthor(value); + } else { + return false; + } + + return true; + } + + @Override public String getParameter(String param) { + String s = super.getParameter(param); + if (s != null) { + return s; + } + + if (param.equals(UC_NAME)) { + return getUcName(); + } else if (param.equals(VERSION_NR)) { + return getVersionNr(); + } else if (param.equals(AUTHOR)) { + return getAuthor(); + } else if (param.equals(UID)) { + return getUid(); + } else { + return null; + } + } + + /** + * @return the trimmed uc-name that only contains word characters + */ + public String getUcNameTrimmed() { + return ucName.replaceAll("\\W", ""); + } + + /** + * @return the trimmed version nr, without spaces + */ + public String getVersionNrTrimmed() { + return versionNr.replaceAll(" ", ""); + } + + /** + * @return the 3 general config parameters + */ + public static String[] getParameters() { + return new String[] {UC_NAME, VERSION_NR, AUTHOR}; + } + + @Override public String validate(Set<String> varNames) { + return null; // nothing to validate here + } + +} diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/ItemType.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/ItemType.java new file mode 100644 index 0000000000000000000000000000000000000000..65bf588200b9d1125e3361c2c6f150786f330a73 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/data/ItemType.java @@ -0,0 +1,54 @@ +package org.universaal.tools.uaalcreator.data; + +import static org.universaal.tools.uaalcreator.data.ConfigItem.*; + +/** + * ItemType specifies the type of a ConfigItem + * + * @author schwende + */ +public enum ItemType { + + PANEL("panel"), + VARIABLE("variable"), + ONTOLOGY_PANEL("ontologypanel"); + + private String text; + + ItemType(String text) { + this.text = text; + } + + /** + * @param s String to create an ItemType from + * @return an instance of ItemType for the given String + */ + public static ItemType fromString(String s) { + if (s.equals("variable")) + return VARIABLE; + else if (s.equals("panel")) + return PANEL; + else if (s.equals("ontologypanel")) + return ONTOLOGY_PANEL; + else + return null; + } + + /** + * @return array containing the names of needed parameters for the ItemType + */ + public String[] getParameters() { + switch (this) { + case PANEL: return new String[] {CAPTION}; + case VARIABLE: return new String[] {NAME, TYPE, LABEL, HOVER}; + case ONTOLOGY_PANEL: return new String[] {CAPTION, NAME, DOMAIN, LABEL, HOVER}; + default: return null; + } + } + + @Override + public String toString() { + return text; + } + +} diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/handlers/UaalCreatorHandler.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/handlers/UaalCreatorHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..95af9251243699a1b0c1aaa6206d9d4c0e8a6c92 --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/handlers/UaalCreatorHandler.java @@ -0,0 +1,21 @@ +package org.universaal.tools.uaalcreator.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.universaal.tools.uaalcreator.actions.UaalCreatorAction; + +/** + * This Handler handles the calls to open the ConfigurationExtractor + * and starts the ExtractorAction + */ +public class UaalCreatorHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + UaalCreatorAction action = new UaalCreatorAction(); + action.run(null); + return null; + } + +} diff --git a/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/view/UaalCreatorView.java b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/view/UaalCreatorView.java new file mode 100644 index 0000000000000000000000000000000000000000..307f388bd24d13bc6ef328d219ff632d5226cc3f --- /dev/null +++ b/uaalfilecreator/org.universaal.tools.uaalcreator/src/org/universaal/tools/uaalcreator/view/UaalCreatorView.java @@ -0,0 +1,207 @@ +package org.universaal.tools.uaalcreator.view; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.ui.part.ViewPart; + +/** + * UaalCreatorView is the ViewPart of the uaal File creator Plugin + */ +public class UaalCreatorView extends ViewPart { + + public static final String ID = "org.universaal.tools.uaalcreator.UaalCreatorView"; + +// private static final String NO_CONFIGURATION_SPECIFIED = "(none selected yet)"; + private static final int BUFFER = 2048; + + + private Label labConfig; + private List listBundles; + + private Composite parentComposite; + + + public UaalCreatorView() { + } + + @Override + public void setFocus() { + // Set the focus + } + + /** + * Create contents of the view part. + * @param parent + */ + @Override + public void createPartControl(Composite parent) { + this.parentComposite = parent; + + GridLayout grid = new GridLayout(); + grid.marginHeight = 0; + grid.marginWidth = 0; + parent.setLayout(grid); + + + Label lab = new Label(parent, SWT.NONE); + lab.setText("1. Please select the required bundles here:"); + + listBundles = new List(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); + + GridData d = new GridData(); + d.widthHint = 250; + d.heightHint = 100; + listBundles.setLayoutData(d); + + Button addBundleBtn = new Button(parent, SWT.NONE); + addBundleBtn.setText("Add a required file"); + addBundleBtn.addListener(SWT.Selection, new Listener() { + @Override public void handleEvent(Event event) { + FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); + fd.setText("Add a required fle"); + fd.setFilterExtensions(new String[] {"*.*"}); + String filepath = fd.open(); + + if (filepath != null) { + listBundles.add(filepath); + } + } + }); + + + + lab = new Label(parent, SWT.NONE); + lab.setText("2. Create the *.uaal file:"); + + + +/* lab = new Label(parent, SWT.NONE); + lab.setText("Please select the configuration ontology here:"); + + labConfig = new Label(parent, SWT.FILL); + labConfig.setText(NO_CONFIGURATION_SPECIFIED); + + Button addConfigBtn = new Button(parent, SWT.NONE); + addConfigBtn.setText("Add the configuration ontology"); + addConfigBtn.addListener(SWT.Selection, new Listener() { + @Override public void handleEvent(Event event) { + FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); + fd.setText("Set the configuration ontology"); + fd.setFilterExtensions(new String[] {"*.owl"}); + String filepath = fd.open(); + + if (filepath != null) { + labConfig.setText(filepath); + parentComposite.layout(); + } + } + }); +*/ + + + + lab = new Label(parent, SWT.NONE); + + + + Button createUaalFileBtn = new Button(parent, SWT.NONE); + createUaalFileBtn.setText("Create file"); + createUaalFileBtn.addListener(SWT.Selection, new Listener() { + @Override public void handleEvent(Event event) { + if (listBundles.getItemCount() <= 0) { + MessageBox messageDialog = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR); + messageDialog.setText("Cannot create *.uaal file"); + messageDialog.setMessage("Please specify the required files\n" + + "before creating the *.uaal file!"); + messageDialog.open(); + return; + } +/* if (labConfig.getText().equals(NO_CONFIGURATION_SPECIFIED)) { + MessageBox messageDialog = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR); + messageDialog.setText("Cannot create *.uaal file"); + messageDialog.setMessage("Please specify the configuration ontology\n" + + "before creating the *.uaal file!"); + messageDialog.open(); + return; + } +*/ + FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); + fd.setText("Specify the filename of the *.uaal file"); + fd.setFilterExtensions(new String[] {"*.uaal"}); + String filepath = fd.open(); + + if (filepath != null) { + saveUaalFile(filepath); + } + } + }); + + } + + /** + * create a *.uaal file (zip file) containing plugins and the configuration ontology + * + * influenced by http://java.sun.com/developer/technicalArticles/Programming/compression/ + */ + private void saveUaalFile(String filepath) { + try { + BufferedInputStream origin = null; + FileOutputStream dest = new + FileOutputStream(filepath); + ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); + byte data[] = new byte[BUFFER]; + File f; + + for (int i=0; i < listBundles.getItemCount(); i++) { + System.out.println("Adding: " + listBundles.getItem(i)); + FileInputStream fi = new FileInputStream(listBundles.getItem(i)); + origin = new BufferedInputStream(fi, BUFFER); + f = new File(listBundles.getItem(i)); + ZipEntry entry = new ZipEntry(f.getName()); + out.putNextEntry(entry); + int count; + while((count = origin.read(data, 0, BUFFER)) != -1) { + out.write(data, 0, count); + } + origin.close(); + } + +/* System.out.println("Adding: " + labConfig.getText()); + FileInputStream fi = new FileInputStream(labConfig.getText()); + origin = new BufferedInputStream(fi, BUFFER); + f = new File(labConfig.getText()); + ZipEntry entry = new ZipEntry(f.getName()); + out.putNextEntry(entry); + int count; + while((count = origin.read(data, 0, BUFFER)) != -1) { + out.write(data, 0, count); + } + origin.close(); +*/ + out.close(); + System.out.println("file saved: " + filepath); + + } catch(Exception e) { + e.printStackTrace(); + } + } + +}