Commit 44c82acf authored by jsimomaa's avatar jsimomaa
Browse files

Experiment around with AERI in Simantics Products

refs #6935

Change-Id: Idcd617129e21d6836865cd2ab40bbd3dc074db59
parent 988ec1a7
<?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.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.simantics.aeri.ui.redmine.core</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>
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
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.simantics.aeri.ui.redmine.core;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.simantics.aeri.redmine.core.settings,
org.simantics.aeri.redmine.core.settings.impl,
org.simantics.aeri.redmine.core.settings.util
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport,
org.eclipse.e4.core.contexts,
org.eclipse.ui.workbench,
org.eclipse.jface,
com.google.guava;bundle-version="15.0.0",
org.eclipse.epp.logging.aeri.core
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.simantics.aeri.redmine.core.internal.Activator
#
bin.includes = .,\
model/,\
META-INF/,\
plugin.xml,\
plugin.properties
jars.compile.order = .
source.. = src/
output.. = bin/
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="settings" nsURI="http://www.simantics.org/emf/redmine-aeri-settings"
nsPrefix="RedmineAERISettings">
<eClassifiers xsi:type="ecore:EClass" name="RedmineAERISettings">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="apiKey" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/org.simantics.aeri.redmine.core/src" modelPluginID="org.simantics.aeri.redmine.core"
modelName="RedmineAERISettings" rootExtendsClass="org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container"
importerID="org.eclipse.emf.importer.ecore" complianceLevel="8.0" copyrightFields="false"
operationReflection="true" importOrganizing="true">
<foreignModel>RedmineAERISettings.ecore</foreignModel>
<genPackages prefix="RedmineAERISettings" basePackage="org.simantics.aeri.redmine.core"
disposableProviderFactory="true" ecorePackage="RedmineAERISettings.ecore#/">
<genClasses ecoreClass="RedmineAERISettings.ecore#//RedmineAERISettings">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute RedmineAERISettings.ecore#//RedmineAERISettings/apiKey"/>
</genClasses>
</genPackages>
</genmodel:GenModel>
#
pluginName = RedmineAERISettings Model
providerName = www.example.org
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
-->
<plugin>
<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated RedmineAERISettings -->
<package
uri="http://www.simantics.org/emf/redmine-aeri-settings"
class="org.simantics.aeri.redmine.core.settings.RedmineAERISettingsPackage"
genModel="model/RedmineAERISettings.genmodel"/>
</extension>
</plugin>
package org.simantics.aeri.redmine.core.di;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.epp.logging.aeri.core.SystemControl;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.simantics.aeri.redmine.core.internal.Activator;
import org.simantics.aeri.redmine.core.settings.RedmineAERISettings;
import org.simantics.aeri.redmine.core.settings.RedmineAERISettingsFactory;
import org.simantics.aeri.redmine.core.settings.RedmineAERISettingsPackage;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
/**
* Context function that computes the {@link RedmineAERISettings}.
*/
public class RedmineAERISettingsCreationFunction implements IContextFunction {
@Override
public Object compute(IEclipseContext localContext, String contextKey) {
RedmineAERISettings settings = RedmineAERISettingsFactory.eINSTANCE.createRedmineAERISettings();
EClass eClass = settings.eClass();
ScopedPreferenceStore instanceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.BUNDLE_ID);
loadFromPreferences(instanceStore, settings, eClass);
registerPreferenceStoreChangeListener(instanceStore, settings, eClass);
registerSettingsChangeListener(instanceStore, settings, new HashSet<EAttribute>());
// register a listener that sends selected changes to the configuration scope store:
// convenience to allow users with different workspaces to reuse the settings
ScopedPreferenceStore configurationStore = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, Activator.BUNDLE_ID);
registerSettingsChangeListener(configurationStore, settings,
ImmutableSet.of(RedmineAERISettingsPackage.eINSTANCE.getRedmineAERISettings_ApiKey()));
// set this settings object in the root context. Effectively replaces this context function.
IEclipseContext systemContext = SystemControl.getSystemContext();
systemContext.set(contextKey, settings);
return settings;
}
private static void registerSettingsChangeListener(final ScopedPreferenceStore store, final RedmineAERISettings settings,
final Set<EAttribute> allowedKeys) {
settings.eAdapters().add(new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
Object feature = msg.getFeature();
if (!(feature instanceof EAttribute)) {
return;
}
EAttribute attr = (EAttribute) feature;
EDataType type = attr.getEAttributeType();
Object value = msg.getNewValue();
// @Nullable
String data = EcoreUtil.convertToString(type, value);
// if empty all keys are allowed:
if (allowedKeys.isEmpty() || allowedKeys.contains(attr)) {
try {
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=494098,
// data may be null and null is not valid as value
if (data == null) {
store.setToDefault(attr.getName());
} else {
store.putValue(attr.getName(), data);
}
store.save();
} catch (Exception e) {
e.printStackTrace();
// log(ERROR_SAVE_PREFERENCES_FAILED, e, attr.getName(), data);
}
}
}
});
}
private static void registerPreferenceStoreChangeListener(final ScopedPreferenceStore store, final RedmineAERISettings settings,
final EClass eClass) {
store.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
EStructuralFeature feature = eClass.getEStructuralFeature(property);
if (feature != null && feature instanceof EAttribute) {
EAttribute attr = (EAttribute) feature;
EDataType type = attr.getEAttributeType();
String string = EcoreUtil.convertToString(type, event.getNewValue());
Object value = EcoreUtil.createFromString(type, string);
settings.eSet(feature, value);
}
}
});
}
private static void loadFromPreferences(final ScopedPreferenceStore store, final RedmineAERISettings settings, final EClass eClass) {
for (EAttribute attr : eClass.getEAllAttributes()) {
EDataType type = attr.getEAttributeType();
String key = attr.getName();
if (!store.contains(key)) {
continue;
}
String value = store.getString(key);
try {
if (attr.isMany()) {
for (String s : convert(value)) {
Object data = EcoreUtil.createFromString(type, s);
((List<Object>) settings.eGet(attr)).add(data);
}
continue;
}
Object data = EcoreUtil.createFromString(type, value);
settings.eSet(attr, data);
} catch (Exception e) {
e.printStackTrace();
// log(ERROR_FAILED_TO_PARSE_PREFERENCE_VALUE, attr, value);
}
}
}
static List<String> convert(String string) {
return Splitter.on(';').omitEmptyStrings().trimResults().splitToList(string);
}
static String convert(List<String> strings) {
return Joiner.on(';').skipNulls().join(strings);
}
}
package org.simantics.aeri.redmine.core.internal;
import org.eclipse.epp.logging.aeri.core.SystemControl;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.simantics.aeri.redmine.core.di.RedmineAERISettingsCreationFunction;
import org.simantics.aeri.redmine.core.settings.RedmineAERISettings;
public class Activator implements BundleActivator {
public static final String BUNDLE_ID = "org.simantics.aeri.redmine.core"; //$NON-NLS-1$
@Override
public void start(BundleContext context) throws Exception {
SystemControl.getSystemContext().set(RedmineAERISettings.class.getName(), new RedmineAERISettingsCreationFunction());
}
@Override
public void stop(BundleContext context) throws Exception {
// TODO Auto-generated method stub
}
}
/**
*/
package org.simantics.aeri.redmine.core.settings;
import org.eclipse.emf.ecore.EObject;
/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>Redmine AERI Settings</b></em>'.
* <!-- end-user-doc -->
*
* <p>
* The following features are supported:
* </p>
* <ul>
* <li>{@link org.simantics.aeri.redmine.core.settings.RedmineAERISettings#getApiKey <em>Api Key</em>}</li>
* </ul>
*
* @see org.simantics.aeri.redmine.core.settings.RedmineAERISettingsPackage#getRedmineAERISettings()
* @model
* @generated
*/
public interface RedmineAERISettings extends EObject {
/**
* Returns the value of the '<em><b>Api Key</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Api Key</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Api Key</em>' attribute.
* @see #setApiKey(String)
* @see org.simantics.aeri.redmine.core.settings.RedmineAERISettingsPackage#getRedmineAERISettings_ApiKey()
* @model
* @generated
*/
String getApiKey();
/**
* Sets the value of the '{@link org.simantics.aeri.redmine.core.settings.RedmineAERISettings#getApiKey <em>Api Key</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Api Key</em>' attribute.
* @see #getApiKey()
* @generated
*/
void setApiKey(String value);
} // RedmineAERISettings
/**
*/
package org.simantics.aeri.redmine.core.settings;
import org.eclipse.emf.ecore.EFactory;
/**
* <!-- begin-user-doc -->
* The <b>Factory</b> for the model.
* It provides a create method for each non-abstract class of the model.
* <!-- end-user-doc -->
* @see org.simantics.aeri.redmine.core.settings.RedmineAERISettingsPackage
* @generated
*/
public interface RedmineAERISettingsFactory extends EFactory {
/**
* The singleton instance of the factory.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
RedmineAERISettingsFactory eINSTANCE = org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsFactoryImpl.init();
/**
* Returns a new object of class '<em>Redmine AERI Settings</em>'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return a new object of class '<em>Redmine AERI Settings</em>'.
* @generated
*/
RedmineAERISettings createRedmineAERISettings();
/**
* Returns the package supported by this factory.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the package supported by this factory.
* @generated
*/
RedmineAERISettingsPackage getRedmineAERISettingsPackage();
} //RedmineAERISettingsFactory
/**
*/
package org.simantics.aeri.redmine.core.settings;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
/**
* <!-- begin-user-doc -->
* The <b>Package</b> for the model.
* It contains accessors for the meta objects to represent
* <ul>
* <li>each class,</li>
* <li>each feature of each class,</li>
* <li>each operation of each class,</li>
* <li>each enum,</li>
* <li>and each data type</li>
* </ul>
* <!-- end-user-doc -->
* @see org.simantics.aeri.redmine.core.settings.RedmineAERISettingsFactory
* @model kind="package"
* @generated
*/
public interface RedmineAERISettingsPackage extends EPackage {
/**
* The package name.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
String eNAME = "settings";
/**
* The package namespace URI.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
String eNS_URI = "http://www.simantics.org/emf/redmine-aeri-settings";
/**
* The package namespace name.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
String eNS_PREFIX = "RedmineAERISettings";
/**
* The singleton instance of the package.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
RedmineAERISettingsPackage eINSTANCE = org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsPackageImpl.init();
/**
* The meta object id for the '{@link org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsImpl <em>Redmine AERI Settings</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsImpl
* @see org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsPackageImpl#getRedmineAERISettings()
* @generated
*/
int REDMINE_AERI_SETTINGS = 0;
/**
* The feature id for the '<em><b>Api Key</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int REDMINE_AERI_SETTINGS__API_KEY = 0;
/**
* The number of structural features of the '<em>Redmine AERI Settings</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int REDMINE_AERI_SETTINGS_FEATURE_COUNT = 1;
/**
* The number of operations of the '<em>Redmine AERI Settings</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int REDMINE_AERI_SETTINGS_OPERATION_COUNT = 0;
/**
* Returns the meta object for class '{@link org.simantics.aeri.redmine.core.settings.RedmineAERISettings <em>Redmine AERI Settings</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for class '<em>Redmine AERI Settings</em>'.
* @see org.simantics.aeri.redmine.core.settings.RedmineAERISettings
* @generated
*/
EClass getRedmineAERISettings();
/**
* Returns the meta object for the attribute '{@link org.simantics.aeri.redmine.core.settings.RedmineAERISettings#getApiKey <em>Api Key</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the attribute '<em>Api Key</em>'.
* @see org.simantics.aeri.redmine.core.settings.RedmineAERISettings#getApiKey()
* @see #getRedmineAERISettings()
* @generated
*/
EAttribute getRedmineAERISettings_ApiKey();
/**
* Returns the factory that creates the instances of the model.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the factory that creates the instances of the model.
* @generated
*/
RedmineAERISettingsFactory getRedmineAERISettingsFactory();
/**
* <!-- begin-user-doc -->
* Defines literals for the meta objects that represent
* <ul>
* <li>each class,</li>
* <li>each feature of each class,</li>
* <li>each operation of each class,</li>
* <li>each enum,</li>
* <li>and each data type</li>
* </ul>
* <!-- end-user-doc -->
* @generated
*/
interface Literals {
/**
* The meta object literal for the '{@link org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsImpl <em>Redmine AERI Settings</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsImpl
* @see org.simantics.aeri.redmine.core.settings.impl.RedmineAERISettingsPackageImpl#getRedmineAERISettings()
* @generated
*/
EClass REDMINE_AERI_SETTINGS = eINSTANCE.getRedmineAERISettings();
/**
* The meta object literal for the '<em><b>Api Key</b></em>' attribute feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EAttribute REDMINE_AERI_SETTINGS__API_KEY = eINSTANCE.getRedmineAERISettings_ApiKey();
}
} //RedmineAERISettingsPackage